If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > SED or AWk to delete lines out of file1 based on values in file2?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-05-04, 16:59
WiccaChic WiccaChic is offline
Registered User
 
Join Date: Jan 2004
Posts: 71
SED or AWk to delete lines out of file1 based on values in file2?

Hello all. I have a big file that I need to delete a number of lines out of. I want to read the values that will determine deletion out of another file, because there are multiple.

Can someone post an example of a sed or awk script to do this?
Reply With Quote
  #2 (permalink)  
Old 08-05-04, 17:25
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,456
Cool

Try something like this:
Code:
for pat in $(cat patterns.txt)
do
  sed "/$pat/d" <bigfile >newbigfile
  mv newbigfile bigfile
done
__________________
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
Reply With Quote
  #3 (permalink)  
Old 08-06-04, 03:37
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
Join Date: Jun 2002
Location: UK
Posts: 525
You could also use grep's -f option...

grep -vf patternFile yourFile > newFile
Reply With Quote
  #4 (permalink)  
Old 08-06-04, 09:51
WiccaChic WiccaChic is offline
Registered User
 
Join Date: Jan 2004
Posts: 71
..

Thanks guys. Someone else suggested the grep thing to me and its so elegant and simple that I am totally amazed.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On