Simpler Navigation for Servers and Operating Systems
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
General
cancel
Showing results for 
Search instead for 
Did you mean: 

using sed to print all words starting with "-l" in a line

Jayesh shah
Frequent Advisor

using sed to print all words starting with "-l" in a line

Hi ,
Does any one know how to print all the words starting with a "-l" on a line (using sed)?

Thanks,
shah
3 REPLIES
Herve BRANGIER
Respected Contributor

Re: using sed to print all words starting with "-l" in a line

Hi

Why do you want to do that with sed ?

I don't if you can but it's simple with :
grep "^-l"

HTH

Herv?


Jayesh shah
Frequent Advisor

Re: using sed to print all words starting with "-l" in a line

I do not want the whole line.I want only the word that begins with a -l.
anyway i got the solution:

awk '{ for( i = 1 ; i <= NF ; i++) { if( $i ~ /^-l/) print $i } }'

Thanks,
Shah
Herve BRANGIER
Respected Contributor

Re: using sed to print all words starting with "-l" in a line

Hi

Ok. Too way to do that with sed or grep :

grep "^PATTERN" file

is the same as

sed -n s/^PATTERN/PATTERN/p

And you can add


| cut -f1 -d' '

to have only the first word only...

Herv?

PS : please don't forget to assign point if
you think my reply is good...