Operating System - Linux
1752865 Members
4005 Online
108791 Solutions
New Discussion юеВ

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 3
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...