Deleting lines from file using another file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Deleting lines from file using another file
# 1  
Old 02-17-2011
Deleting lines from file using another file

Hi All,
Need your Help. when i tried deleting lines from one file using another file i got this below error:
Code:
$  sed "s/\(.*\)/\/^&$\/d/" a.txt > x.tmp
$  sed -f x.tmp b.txt > target.txt
sed: 0602-405 There are too many commands for the /^111111|.12|.00$/d function.

a.txt:
Code:
111111|.11|.00
222222|2.22|.00
333333|.00|.00
444444|.00|.00
555555|.00|.00
666666|.00|.00

b.txt
Code:
111111|.11|.00
333333|.00|.00
777777|.01|.21
444444|.00|.00
666666|.00|.00


Last edited by Franklin52; 02-17-2011 at 03:41 AM.. Reason: Please use code tags
# 2  
Old 02-17-2011
what do you wanna do?what result do you expect?
# 3  
Old 02-17-2011
My result should be:
Target1:
Code:
222222|2.22|.00
555555|.00|.00

Target2:
Code:
777777|.01|.21


Last edited by Yogesh Sawant; 04-14-2011 at 08:18 AM.. Reason: added code tags
# 4  
Old 02-17-2011
awk:
Code:
awk 'NR==FNR{a[$0];next}!($0 in a)' a b

# 5  
Old 02-17-2011
Either:
Code:
fgrep -v -f b.txt a.txt > target1
fgrep -v -f a.txt b.txt > target2

Or:
Code:
< a.txt b.txt b.txt sort | uniq -u > target1
< a.txt a.txt b.txt sort | uniq -u > target2

Andrew
# 6  
Old 02-17-2011
Code:
awk 'NR==FNR{a[$0];next}!($0 in a)' b.txt a.txt > Target1
awk 'NR==FNR{a[$0];next}!($0 in a)' a.txt b.txt > Target2

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Deleting lines of a file if they exist in another file

I have a reference file that needs to remain static and another file that may or may not have duplicate rows that match the reference file. I need help with a command that will delete any duplicate rows from the second file while leaving reference file intact For example reference file would... (4 Replies)
Discussion started by: bjdamon
4 Replies

2. Shell Programming and Scripting

deleting lines from file

We have a server that logs transactions to a file. I want to write a script that will delete the first 50 lines of the file daily without renameing the file or moving the file. (8 Replies)
Discussion started by: daveisme
8 Replies

3. Shell Programming and Scripting

Deleting lines in a flat file

Hi Friends I have a flat file which has sentence like "Notice generated". It can be anywhere in the flat file. What I want to do is, I want to delete all the lines which are above sentence "Notice generated". How can I do it. Kindly advice. Anushree (5 Replies)
Discussion started by: anushree.a
5 Replies

4. UNIX for Advanced & Expert Users

Deleting lines from a file

How I can delete 100 lines anywhere in a file without opening a file and without renaming the file. (11 Replies)
Discussion started by: Nirgude07
11 Replies

5. Shell Programming and Scripting

Deleting lines from file using another file

I am having a requirement like File A contains All the records eg., ONE TWO THREE FOUR FIVE SIX SEVEN EIGHT NINE TEN File B contains invalid records of File A eg., TWO FOUR FIVE SEVEN (7 Replies)
Discussion started by: dinesh1985
7 Replies

6. UNIX for Dummies Questions & Answers

Deleting whole lines from a file

I have a file with 65 sets of 35 coordinates, and would like to isolate these coordinates so that I can easily copy the coordinates to another file. The problem is, I've got a 9 line header before each set of coordinates (so each set is 44 lines long). There are a zillion threads out there about... (3 Replies)
Discussion started by: red baron
3 Replies

7. Shell Programming and Scripting

Deleting lines inside a file without opening the file

Hi, Just consider there are around 10 lines in a file. Now is it possible to delete the first 2 lines in the file without opening the file. No matter whatever the content of the file is, I just wanna delete the first 2 lines without opening the file. Is that possible? If so, please help me out.... (3 Replies)
Discussion started by: toms
3 Replies

8. Shell Programming and Scripting

Deleting lines in a file

How do I delete all the lines after the line containing text ***DISCLOSURES*** . I want to delete this line too. Thank you (2 Replies)
Discussion started by: reachsamir
2 Replies

9. Shell Programming and Scripting

Deleting last 2 lines from the file.

Hi I have a file & always I need to remove or delete last 2 lines from that file. So in a file if I have 10 lines then it should return me first 8 lines. Can someone help me? (4 Replies)
Discussion started by: videsh77
4 Replies

10. Shell Programming and Scripting

Deleting specific lines in a file

I have a file which has some lines starting with a particular word. I would like to delete 5 lines before each such line containing that particular word. eg: line1 line2 line3 line4 line5 line6 "particular word"... I would like to delete line2-line6 and all such occurences in that... (4 Replies)
Discussion started by: ramu_1980
4 Replies
Login or Register to Ask a Question