![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 08:39 AM |
| echo "ABC" > file1.txt file2.txt file3.txt | ganapati | UNIX for Dummies Questions & Answers | 4 | 01-29-2008 09:36 PM |
| Awk Compare f1,f2,f3 of File1 with f1 of File2 | RacerX | Shell Programming and Scripting | 6 | 11-08-2007 10:34 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
while read WORD
do sed '/'$WORD'/d' file2 done < file1 |
|
#3
|
|||
|
|||
|
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? |
|
#4
|
||||
|
||||
|
Use a for loop?
Code:
for Word in `ls <unique list of words filename>` do sed -e '$Word/d' < file2 > file3 done |
|
#5
|
||||
|
||||
|
See if this works:
Code:
cp file2 file3 while read WORD do sed '/'$WORD'/d' < file3 > TMP_00 mv TMP_00 file3 done < file1 Code:
while read WORD do cmd="$cmd -e /$WORD/d" done < file1 `sed $cmd < file2 > file3` |
|
#6
|
|||
|
|||
|
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! |
|
#7
|
||||
|
||||
|
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. |
||||
| Google The UNIX and Linux Forums |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|