Let's say I'm doing a grep and it returns this line:
Invalid value (48) on line 3
How can I easily pull that value 48 into a variable in Bourne shell?
Let's say I'm doing a grep and it returns this line:
Invalid value (48) on line 3
How can I easily pull that value 48 into a variable in Bourne shell?
If you are sure that the pattern is always to get the value in the first pair of parenthesis, then cut is your best friend.
myvar=$(echo 'Invalid value (48) on line 3' | cut -d\( -f2 | cut -d\) -f1)
this extracts the value between the parens.
$() is not part of SVID and thus not strictly "Bourne Shell" only. It's defined in POSIX though.
– slhck
Aug 13 '13 at 18:13
sh and not Bash and companions.
– slhck
Aug 13 '13 at 18:18