Comparing two files script and finding the unmatched data

robert patrik

I am having two .txt files with data stored in the format

1.txt

ASF001-AS-ST73U12
ASF001-AS-ST92U14
ASF001-AS-ST105U33
ASF001-AS-ST107U20

and

2.txt

ASF001-AS-ST121U21
ASF001-AS-ST130U14
ASF001-AS-ST73U12
ASF001-AS-ST92U14

` I need to find the files which are in 1.txt but not in 2.txt.

I tried to use

diff -a --suppress-common-lines -y 1.txt 2.txt > finaloutput

but it didn't work

anubhava

Rather than diff you can use comm here:

comm -23 <(sort 1.txt) <(sort 2.txt)
ASF001-AS-ST105U33
ASF001-AS-ST107U20

Or this awk will also work:

awk 'FNR==NR {a[$1];next} $1 in a{delete a[$1]} END {for (i in a) print i}' 1.txt 2.txt
ASF001-AS-ST107U20
ASF001-AS-ST105U33

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

TOP Ranking

HotTag

Archive