Delete the records in file based on lookup file.

Hi
I have two files one.txt and two.txt
one.txt

123
324
456
235
456

two txt

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..

abc one 000 122 abc
abc one 000 111 abc

Pls help us to resolve this scenario by unix script.

one way:

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

Hello Ganesh L,

Following may also help you in same.

awk 'FNR==NR{X[$4]=$0;next} ($1 in X){;delete X[$1]} END{for(i in X){print X}}' two.txt one.txt

Output will be as follows.

abc one 000 111 abc
abc one 000 122 abc

Thanks,
R. Singh

1 Like