Arun
Arun

Reputation: 1220

Bash compare two different files and get non-matching lines from second

I know how to compare two files and get the matching line result from 2nd ( file_2.txt) file using awk

Run Method : $awk -F"," 'NR==FNR{a[$1];next} $1 in a' file_1.txt file_2.txt

$cat file_1.txt
95335df46cfdb345c0214296e0043c00,5,M,N
a0af947a85e6895dab70eaec136cfed2,4,P,Q

$cat file_2.txt
77f673137c17b4b0405d13060e9715a3,5,X,Y
874d51610c15975c82c081aba0b096c3,5,A,M
95335df46cfdb345c0214296e0043c00,5,M,N

How can i compare the second file file_2.txt against the first file_1.txt and get the non-matched lines from the second file ( file_2.txt ) ?

Any suggestions please ?

Upvotes: 1

Views: 1347

Answers (1)

CWLiu
CWLiu

Reputation: 4043

$ awk -F"," 'NR==FNR{a[$1];next} !($1 in a)' file_1.txt file_2.txt
77f673137c17b4b0405d13060e9715a3,5,X,Y
874d51610c15975c82c081aba0b096c3,5,A,M

Upvotes: 2

Related Questions