The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
insert file2 after line containing patternX in file1 repudi8or Shell Programming and Scripting 5 04-18-2008 10:35 AM
Search, replace string in file1 with string from (lookup table) file2? gstuart Shell Programming and Scripting 2 04-11-2008 11:32 AM
match value from file1 in file2 myguess21 Shell Programming and Scripting 2 02-21-2008 07:39 AM
echo "ABC" > file1.txt file2.txt file3.txt ganapati UNIX for Dummies Questions & Answers 4 01-29-2008 08:36 PM
Awk Compare f1,f2,f3 of File1 with f1 of File2 RacerX Shell Programming and Scripting 6 11-08-2007 09:34 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-16-2003
Registered User
 

Join Date: Aug 2001
Location: Raleigh, nC
Posts: 28
Stumble this Post!
delete lines from file2 beginning w/file1

I've been searching around here and other places, but can't put this together...

I've got a unique list of words in file 1 (one word on each line).
I need to delete each line in file2 that begins with the word in file1.

I started this way, but want to know how to use file1 words instead of supplying a keyword:

sed -e '????/d' < file2 > file3

sed -e '`cat file1`/d' 012703.csv 061603.csv

I want to put something at the ???? that reads each line of file1. Any help would be greatly appreciated!

LSM
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 06-16-2003
oombera's Avatar
Have a day :|
 

Join Date: Aug 2002
Location: Cleveland, OH
Posts: 804
Stumble this Post!
while read WORD
do
sed '/'$WORD'/d' file2
done < file1
Reply With Quote
  #3 (permalink)  
Old 06-17-2003
Registered User
 

Join Date: Aug 2001
Location: Raleigh, nC
Posts: 28
Stumble this Post!
what about file3?

Thanks! I want to put the new file2 (with the lines already deleted) into a new file3. Also, I need to make sure $WORD is at the beginning of the line. I tried the below but got an empty file3.

while read WORD
do
sed '/$WORD/d' file2 > file3
done < file1

Any suggestions?
Reply With Quote
  #4 (permalink)  
Old 06-17-2003
Ralf's Avatar
Registered User
 

Join Date: Oct 2002
Posts: 34
Stumble this Post!
Use a for loop?

Code:
for Word in `ls <unique list of words filename>`
do

 sed -e '$Word/d' < file2 > file3

done
Reply With Quote
  #5 (permalink)  
Old 06-17-2003
oombera's Avatar
Have a day :|
 

Join Date: Aug 2002
Location: Cleveland, OH
Posts: 804
Stumble this Post!
See if this works:
Code:
cp file2 file3
while read WORD
do
  sed '/'$WORD'/d' < file3 > TMP_00
  mv TMP_00 file3
done < file1
or this, which may be faster:
Code:
while read WORD
do
  cmd="$cmd -e /$WORD/d"
done < file1

`sed $cmd < file2 > file3`
Reply With Quote
  #6 (permalink)  
Old 06-19-2003
Registered User
 

Join Date: Aug 2001
Location: Raleigh, nC
Posts: 28
Stumble this Post!
That works! Now I want to make sure that $WORD is at the beginning of the line. Shouldn't this work?

while read WORD
do
cmd="$cmd -e /^$WORD/d"
done < file1

`sed $cmd < file2 > file3`

THIS IS file1 CONTENTS:

15
16
17

THIS IS file2 CONTENTS:

15
16
What is the meaning of 17
18

I WANT file3 TO BE WRITTEN AS:

What is the meaning of 17
18

That is... lines 1 and 2 were deleted because they began with 15 and 16... Right now I'm getting file3 that looks like this:

18

Thanks for any help!
Reply With Quote
  #7 (permalink)  
Old 06-19-2003
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,426
Stumble this Post!
I can't duplicate your failure. I get the two lines that you want. What shell are you using? Can you try it with ksh or bash?

And you don't need those backquotes around the sed command. Try getting rid of those.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 11:44 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0