USING sed to remove multiple strings/words from a line

Hi
I use sed comnand to remove occurance of one workd from a line.
However I need to removed occurance of dufferent words in ne line.

Original-1

Hi this is the END of my begining 

Comand

sed s/"END"/"start"/g

Output-1

Hi this is the start of my beginig

But I have more than one text that I need to remove on the line:

example of a line:

User Name is TOM And Application type is PLAY the position is <END>

I want to remove "Name is" as well as "type is" as well as "<END>"

Output Should look like this:

User TOM And Application PLAY the position is 

I can do several SED commands .. but there must be an easy way to combine all this into one sed command?

How do u combine multiple strings to be replaced into one line?

Thanking you in advance

sed 's/whatever/something/g;s/whateverelse/somethingelse/g' myFile

I cannot use the ; to combine the sed command multiple times .. I'm using sed in context of a PIPE so no I tried that and that is not what I 'm looking for .. I can do lultiple PIPES .. example

cat file | sed  s/a/b/g  | sed s/c/d//g 

This will not work

cat file | sed s/a/b/g;sed s/c/d//g

---------- Post updated at 03:02 PM ---------- Previous update was at 03:01 PM ----------

there must be another way to combine the sed command???????

cat file | sed 's/\(Name is\|type is\|<END>\)//g'

this should do what you want.
EDIT:

cat file | sed 's/\(Name is\s*\|type is\s*\|<END>\)//g

this one should remove the trailing spaces as well, if you want that

There is a difference between your not working

... | sed s/a/b/g;sed s/c/d/g

and vgersh99's multiple sed commands within one sed script

... | sed 's/a/b/g; s/c/d/g'

HI thanks Demios - To be exact I tried ur command .. something not going right ?

this is the command I'm using and the output

grep -i overflow server.log | sort | grep user1 
<xyzalert.1.s2ss: Info: Fri Dec 06  09:21:18 2013> User mtietjan at position 170.198.18.74/net on host 170.198.18.74 using application 91 has been disconnected.<END>

I need to get rid of the following .1.s2ss: and < and .<END>

I tried this . .there seems to be a syntax maybe I have to escape some of the periods and special charatcer .. not sure really . .tried few different combination and not working

grep -i overflow p2ps.log | sort | grep mtietjan | sed 's/\(/.1.p2ps: Info:\|<end>\)//g'

try:

sed 's/\(\.1\.p2ps: Info:\|<END>\)//g'

LMK how it works out

1 Like

thanks deimos ... it works !!!

glad to hear that...no problem, you're welcome

Note: \| alternation in sed is a GNU-only extension, so this only works with GNU sed.