goh3ah3dee
goh3ah3dee

Reputation: 1

Parse config file

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

Answers (3)

vara
vara

Reputation: 836

Using this concept

sed "s/^[a-z].* ([a-z].*== '\([a-z].*\)' [a-z].*== '\([a-z].*\)')$/\1/" inputfile

Upvotes: 0

Ansgar Wiechers
Ansgar Wiechers

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

iruvar
iruvar

Reputation: 23364

the following should do the trick

sed -nr "s/[^']*'([^']*)'.*/\1/p" test

Upvotes: 1

Related Questions