I'm using grep to extract parts from a file but I'm having trouble making it work properly. From a string,
something0( something1
I want to extract something0. This works fine on some input,
echo 'a b( c d' | grep -Po '(?m)^.+?(?=\(.+)' #outputs 'a b'
But not so well on other input,
echo 'a b( )c d( e f' | grep -Po '(?m)^.+?(?=\(.+)' #outputs 'a b' and '( ) c d'
How would I make grep only return the first match or improve my regex? Piping greps output to,
head -n 1
is not an alternative since grep will read an entire file with these lines and if I'm not misstaking this will only output the first ever match in the file. It's okey to assume that something0 doesn't contain any '('.
Thanks.
-P