Unix/Linux Go Back    


UNIX for Dummies Questions & Answers This forum is closed for new posts. Please post beginner questions to learn unix and learn linux in this forum UNIX for Beginners Questions & Answers

sed option to delete two words within a file

UNIX for Dummies Questions & Answers


 
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 04-14-2002
klannon klannon is offline
Registered User
 
Join Date: Mar 2002
Last Activity: 6 May 2002, 2:20 PM EDT
Location: MA
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
sed option to delete two words within a file

Could someone please help me with the following.

I'm trying to figure out how to delete two words within a specific file using sed.

The two words are directory and named.

I have tried the following:

sed '/[directory|named]/d' sedfile
sed '/[directory named]/d' sedfile

both of these options do not work.....


Thanks
Sponsored Links
    #2  
Old Unix and Linux 04-15-2002
inpavan inpavan is offline
Registered User
 
Join Date: Sep 2001
Last Activity: 18 December 2002, 6:21 AM EST
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Are you trying to delete the line containing the word(s) or trying to delte the words only.

sed 's/yourword//g' yourfile > newfile - To delte the words only
sed 's/yourword/d' yourfile > new file - to delte the line containing the words

Use - s/firstword.*secondword//g - For matching two words.

Hope this is useful.
Sponsored Links
    #3  
Old Unix and Linux 04-15-2002
klannon klannon is offline
Registered User
 
Join Date: Mar 2002
Last Activity: 6 May 2002, 2:20 PM EDT
Location: MA
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Still having some trouble deleting firstword

First off, I want to say thank inpavan for the help. To answer inpavens question regarding what I am trying to delete, I am trying to delete two words within a file. The file is about 80 lines in length. I do not want to delete any line just the words discovery and named.

1. The sed 's/yourword//g' yourfile > newfile - To delte the words only worked to delete either word, but only one word at a time.

2. The use of sed 's/firstword.*secondword//g' filename worked only to delete the secondword, the first word was ignored.

I am trying to figure out how to delete two words at the same time.

Again thanks for the help.

klannon


Linux Linux
    #4  
Old Unix and Linux 04-15-2002
peter.herlihy peter.herlihy is offline
Registered User
 
Join Date: Nov 2001
Last Activity: 1 August 2006, 11:51 AM EDT
Location: New Zealand
Posts: 333
Thanks: 0
Thanked 0 Times in 0 Posts
The -e flag with sed can be used to specify multiple actions.... so try

sed -e s/firstword//g -e s/secondword//g myfile > new_myfile

Keep in mind that if you want the spaces that may have appeared before or after the words to go as well - then add the spaces to the sed commands...... i.e s/firstword //g
Sponsored Links
    #5  
Old Unix and Linux 04-15-2002
klannon klannon is offline
Registered User
 
Join Date: Mar 2002
Last Activity: 6 May 2002, 2:20 PM EDT
Location: MA
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks for the help.

Peter,

I just wanted to say thanks, you answered my question. This site is execellent to budding unix users.

Best Regards,

Ken
Sponsored Links
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Using Sed to Delete Words in a File SkySmart Shell Programming and Scripting 5 03-11-2011 12:16 PM
sed how to delete between two words within a file martinsmith UNIX for Dummies Questions & Answers 4 06-28-2010 08:30 AM
Need to delete words in a file raghav1982 Shell Programming and Scripting 4 07-13-2009 01:00 AM
option to delete .tar file while extracting vickylife Solaris 5 01-19-2009 08:55 PM
How to delete first 10 words from file sentak UNIX for Advanced & Expert Users 6 10-29-2008 07:32 PM



All times are GMT -4. The time now is 07:29 PM.