tags:

views:

196

answers:

2

hi

how to get the second word (string) after "=" separator by sed (need to ignore spaces)

for example

   echo " bla bla word word1 = strin1 string2 " | sed .....

I should get string2

another example

    echo " bla bla word word1 =swhsw 123  " | sed .....

I should get 123

please advice lidia

+1  A: 

I believe awk is a better solution for this case, simply use.

echo "bla bla word word1 = strin1 string2" | awk -F"=" '{print $2}' | awk '{print $2}'
Anders
after I perfrom echo "bla bla word word1 = strin1 string2" | awk -F"=" '{print $2}' I get strin1 string2 (why its not print only string2 ?)
lidia
hi anders : I need only the second word after seperator not all words after seperator , can you change your awk according to thatlidia
lidia
@lidia fixed. In the example it prints string2.
Anders
A: 
$ echo " bla bla word word1 = strin1 string2 " | sed 's/.[^=]*=\(.[^ \t]*\)[ \t]*\(.[^ \t]*\)\(.*\)/\2/'
string2


$ echo " bla bla word word1 =swhsw 123  " | awk -F"=" '{split($2,a," ");print a[2]}'
123

And how about you start reading up on how to use sed/awk ?

ghostdog74