Reputation: 1
I would like to get the first pattern in single quote.
$ cat test
if (response == 'good' and name == 'john')
With this command, I get the last pattern in single quote :
$ sed -nr "s/.*'(.*)'.*/\1/p" test
john
I want it to return
good
Upvotes: 0
Views: 225
Reputation: 836
Using this concept
sed "s/^[a-z].* ([a-z].*== '\([a-z].*\)' [a-z].*== '\([a-z].*\)')$/\1/" inputfile
Upvotes: 0
Reputation: 200293
There are several ways to achieve this. For instance awk
:
awk -F"'" '{print $2}'
or Perl
:
perl -ne 'print "$1\n" if /'"'"'(.*?)'"'"'/;'
Upvotes: 1
Reputation: 23364
the following should do the trick
sed -nr "s/[^']*'([^']*)'.*/\1/p" test
Upvotes: 1