Delete the records in file based on lookup file.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Delete the records in file based on lookup file.
# 1  
Old 01-21-2015
Wrench Delete the records in file based on lookup file.

Hi
I have two files one.txt and two.txt
one.txt
Code:
123
324
456
235
456

two txt
Code:
abc one 000 123 abc
abc one 000 456 abc
abc one 000 122 abc
abc one 000 111 abc

My question here is, the records which are present in one.txt has to deleted in second file two.txt
my output result should be..

Code:
abc one 000 122 abc
abc one 000 111 abc

Pls help us to resolve this scenario by unix script.
Moderator's Comments:
Mod Comment please use code tags

Last edited by jim mcnamara; 01-21-2015 at 04:35 PM..
# 2  
Old 01-21-2015
one way:

Code:
awk 'FILENAME=="one.txt" {arr[$1]++}
        FILENAME=="two.txt" {
              if($4 in arr){next}
              print $0
         }  ' one.txt  two.txt > new2.txt

This User Gave Thanks to jim mcnamara For This Post:
# 3  
Old 01-22-2015
Hello Ganesh L,

Following may also help you in same.
Code:
awk 'FNR==NR{X[$4]=$0;next} ($1 in X){;delete X[$1]} END{for(i in X){print X[i]}}' two.txt one.txt

Output will be as follows.
Code:
abc one 000 111 abc
abc one 000 122 abc

Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Delete records based on a text file from a text file

Hi Folks, I am a novice and need to build a script in bash. I have 2 text files data.txt file is big file, column 2 is the we need to search and delete in the output. The filter file contains the rows to be deleted. Data.txt state city zone Alabama Huntsville 4 California SanDiego 3... (3 Replies)
Discussion started by: tech_frk
3 Replies

2. UNIX for Dummies Questions & Answers

Delete records from a big file based on some condition

Hi, To load a big file in a table,I have a make sure that all rows in the file has same number of the columns . So in my file if I am getting any rows which have columns not equal to 6 , I need to delete it . Delimiter is space and columns are optionally enclosed by "". This can be ... (1 Reply)
Discussion started by: hemantraijain
1 Replies

3. Shell Programming and Scripting

Lookup on large file based on a temp file

hello guys Please help me with the below issue I have two files one base file another lookupfile base file abc-001 bcd-001 cde-001 Lookupfile abc-001|11|12 abc-001|11|12 abc-001|11|12 (6 Replies)
Discussion started by: Pratik4891
6 Replies

4. Shell Programming and Scripting

Need unix commands to delete records from one file if the same record present in another file...

Need unix commands to delete records from one file if the same record present in another file... just like join ... if the record present in both files.. delete from first file or delete the particular record and write the unmatched records to new file.. tried with grep and while... (6 Replies)
Discussion started by: msathees
6 Replies

5. UNIX for Dummies Questions & Answers

Filtering records from 1 file based on some manipulation doen on second file

Hi, I am looking for an awk script which should help me to meet the following requirement: File1 has records in following format INF: FAILEd RECORD AB1234 INF: FAILEd RECORD PQ1145 INF: FAILEd RECORD AB3215 INF: FAILEd RECORD AB6114 ............................ (2 Replies)
Discussion started by: mintu41
2 Replies

6. Shell Programming and Scripting

select records from one file based on a second file

Hi all: I have two files: file1: 74 DS 9871 199009871 1 1990 4 1 165200 Sc pr de te sa ox 1.0 1.0 13.0000 35.7560 5.950 3.0 3.0 13.0100 35.7550 5.970 ** 74 DS 99004 74DS99004 6738 1990 4 1 165200 Eb pr de te sa ox 1.0 1.0 13.0000 ... (7 Replies)
Discussion started by: rleal
7 Replies

7. Shell Programming and Scripting

SED based on file lookup

Newb here trying to figure this one out. :confused: I am trying to create a SED (or some other idea) line that will replace the data field if the original text is seen in a separate text file. The lookup file would be line delimted. For example: sed 's/<if in file>/YES/' File structure:... (3 Replies)
Discussion started by: sdlennon
3 Replies

8. UNIX for Dummies Questions & Answers

Use records from one file to delete records in another file

file_in_1: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 file_in_2: 9 10 11 12 21 22 23 24 1 2 3 4 17 18 19 20 file_out: (5 Replies)
Discussion started by: kenneth.mcbride
5 Replies

9. Shell Programming and Scripting

Splitting a file based on the records in another file

All, We receive a file with a large no of records (records can vary) and we have to split it into two files based on another file. e.g. File1: UHDR 2008112 "25187","00000022","00",21-APR-1991,"" ,"D",-000000519,+0000000000,"C", ,+000000000,+000000000,000000000,"2","" ... (2 Replies)
Discussion started by: er_ashu
2 Replies

10. Shell Programming and Scripting

delete records from a file

I have a big file with "|" delimiter. I want to delete all the records that have 'abc' in the 2nd field. How can i do that? I am not abe to open it in VI that is why i need to do it from outside. Please suggest (6 Replies)
Discussion started by: dsravan
6 Replies
Login or Register to Ask a Question