Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sed commands in several lines 2

Status
Not open for further replies.

atojaf

Programmer
Mar 7, 2006
18
US
Could you please tell me how to separate these commands in several lines. Each line starting with the -e. I am running this on a Korn shell. thanks again.


cat test.txt | sed -e '/log/ s/log/ /g' -e '/car/ s/car/ /g' -e '/GO/ s/GO/ /g' -e '/ON/ s/ON/ /g'

 
sed '
/log/s/log/ /g
/car/s/car/ /g
/GO/s/GO/ /g
/ON/s/ON/ /g
' test.txt

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
isn't
sed -e '/log/ s/log/ /g' the same as
sed -e 's/log/ /g' ?

and
sed -e 's/log/ /g' the same as
sed 's/log/ /g' ?

I would use:

Code:
sed 's/log/ /g;s/car/ /g;s/GO/ /g;s/ON/ /g' test.txt
which can be reduced father with ORs:
Code:
sed 's/\(log\|car\|GO\|ON\)/ /g' test.txt

seeking a job as java-programmer in Berlin:
 
Hi

The -e is require only if you write multiple commands as separate command line parameters, as in atojaf's example. That way without -e the second and subsequent codes would be treated as filenames.

And there is no need to capture the matched expressions with parenthesis ( () ).
Code:
sed 's/log\|car\|GO\|ON/ /g' test.txt

[gray]# or abit more readable in GNU sed[/gray]
sed -r 's/log|car|GO|ON/ /g' test.txt

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top