I have a string, for example
"Icecream123 AirplaneBCD CompanyTL1 ComputerYU1"
Let's say I know that my string will contain for sure the substring IceCream but I don't know what follows it.
It might be 123 as in my example or it might be something different.
While I can use grep to detect if "Icecream" substring exists in my string with the following command
echo $string | grep -oF 'Icecream';
Which will print
Icecream
I want with a command to get it to print the whole substring, which in my example is
Icecream123
Of course what follows Icecream is random and not known beforehand so I can't just do
$SUBSTRING=$(echo $string | grep -oF 'Icecream')
$SUBSTRINGTRAIL=123
echo $SUBSTRING$SUBSTRINGTRAIL
Icecream123 AirplaneBCD
you want stopped at123
. Is that because there's a space after the 3, or something else? – Jeff Schaller Jun 08 '18 at 22:07