USING sed to remove multiple strings/words from a line

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting USING sed to remove multiple strings/words from a line
# 1  
Old 01-17-2014
USING sed to remove multiple strings/words from a line

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.

Hi this is the END of my begining

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

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

Last edited by Scrutinizer; 01-17-2014 at 04:56 PM.. Reason: code tags
# 2  
Old 01-17-2014
sed 's/whatever/something/g;s/whateverelse/somethingelse/g' myFile

# 3  
Old 01-17-2014
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???????

Last edited by Scott; 01-17-2014 at 05:53 PM.. Reason: Code tags
# 4  
Old 01-17-2014
cat file | sed 's/\(Name is\|type is\|<END>\)//g'

this should do what you want.
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

Last edited by Deimos; 01-17-2014 at 05:22 PM..
# 5  
Old 01-17-2014
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'

# 6  
Old 01-17-2014
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 on host 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'

Last edited by Scott; 01-17-2014 at 05:54 PM.. Reason: Added code tags [19th time]
# 7  
Old 01-17-2014
sed 's/\(\.1\.p2ps: Info:\|<END>\)//g'

LMK how it works out
This User Gave Thanks to Deimos For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

sed parser behaving strange on replacing multiple words in multiple files

Discussion started by: sammy777888
1 Replies

2. Shell Programming and Scripting

sed Find and Replace Text Between Two Strings or Words

I am looking for a sed in which I can recognize all of the text in between two indicators and then replace it with a place holder. For instance, the 1st indicator is a list of words "no|noone|havent" and the 2nd indicator is a list of punctuation ".|,|!".From a sentence such as "noone... (3 Replies)
Discussion started by: owwow14
3 Replies

3. Shell Programming and Scripting

Search words in multiple file line by line

Hi All I have to search servers name say like 1000+ "unique names" line by line in child.txt files in another file that is a master file where all server present say "master.txt",if child.txt's server name matches with master files then it print yes else no with server name. (4 Replies)
Discussion started by: netdbaind
4 Replies

4. Shell Programming and Scripting

Remove last few words from Line

Hi I would like to remove last few words from File Could anybody Help on it. ps -ef | grep mgr.prm | awk '{print $10}' /opt/app/dummyd/xyz/dirprm/mgr.prm /opt/app/dummy/xyz/dirprm/mgr.prm /opt/app/dummy/xyz/dirprm/mgr.prm I want output like /opt/app/dummyd/xyz... (4 Replies)
Discussion started by: tapia
4 Replies

5. Shell Programming and Scripting

Remove all words after first space from each line

My file looks like: asd absjdd sdff vczxs wedssx c dasx ccc I need to keep asd sdff wedssx dasx How do I do that experts?:wall::wall: (1 Reply)
Discussion started by: hakermania
1 Replies

6. Shell Programming and Scripting

delete repeated strings (tags) in a line and concatenate corresponding words

Hello friends! Each line of my input file has this format: word<TAB>tag1<blankspace>lemma<TAB>tag2<blankspace>lemma ... <TAB>tag3<blankspace>lemma Of this file I need to eliminate all the repeated tags (of the same word) in a line, as in the example here below, but conserving both (all) the... (2 Replies)
Discussion started by: mjomba
2 Replies

7. UNIX for Dummies Questions & Answers

best method of replacing multiple strings in multiple files - sed or awk? most simple preferred :)

Hi guys, say I have a few files in a directory (58 text files or somthing) each one contains mulitple strings that I wish to replace with other strings so in these 58 files I'm looking for say the following strings: JAM (replace with BUTTER) BREAD (replace with CRACKER) SCOOP (replace... (19 Replies)
Discussion started by: rich@ardz
19 Replies

8. Shell Programming and Scripting

How to remove all words from a matching word in a line?

Hi Guys, :p I have a file like this: 2010-04-25 00:00:30,095 INFO - ]- start process U100M4 2010-04-25 00:00:30,096 DEBUG - ] -- call EJB 2010-04-25 00:00:30,709 INFO - - end processU100M4 2010-04-25 00:00:30,710 DEBUG - got message=Sorry I want to out put format. 2010-04-25... (5 Replies)
Discussion started by: ooilinlove
5 Replies

9. Shell Programming and Scripting

remove duplicate words in a line

Hi, Please help! I have a file having duplicate words in some line and I want to remove the duplicate words. The order of the words in the output file doesn't matter. INPUT_FILE pink_kite red_pen ball pink_kite ball yellow_flower white no white no cloud nine_pen pink cloud pink nine_pen... (6 Replies)
Discussion started by: sam_2921
6 Replies

10. Shell Programming and Scripting

remove first few words from a line

Hi All, Sample: 4051 Oct 4 10:03:36 AM 2008: TEST: end of testcase Checking Interface after reload, result fail I need to remove first 10 words of the above line and output should be like Checking Interface after reload, result fail Please help me in this regard. Thanks, (4 Replies)
Discussion started by: shellscripter
4 Replies
Login or Register to Ask a Question