Compare two txt files,mismatches will be in new txt files

Hi,
Below are the sample data for txt files.

txt file 1

Partnumber|catgroup_id
10001082|46016
10001093|4680
10001093|386003
10001093|463004
10003251|683
10003251|63005
10003252|463005
10003252|4683
10003260|463005
10003260|4683
10003264|4683
10003264|463005
13420000|67
23450986|1234

txtfile 2

Partnumber|catgroup_id
10001093|4680
10001093|234
10001093|40
10003251|4683
10003251|463005
10003252|46
10003252|4683
10003260|463005
10003260|468
13420000|67
23450986|123

For each partnumber present in txt file 2,we need to compare catgroup_ids for both the files corresponding to the partnumber,mismatches catgroupids and partnumber from txt file 2 will have to store in new txt file
*One part number might have multiple catgroupids.

Thanks for the help in advance.

Regards
Ankita

I guess I am lost with the long sentence there :slight_smile:

Can you give me a sample output needed?

-----------------------------------

This could help :slight_smile:

awk -F"|" 'FNR==NR{a[$1]++;next}!a[$1]' file1 file2

Hi,

Thanks for the command.

Output file would be-

10001093|234
10001093|40
10003251|4683
10003251|463005
10003252|46
10003260|468
23450986|123

Ankita

$ awk -F"|" 'FNR==NR{A[$1 FS $2];next}!(($1 FS $2) in A)' file1 file2 
$ grep -v -f <(sort file1) <(sort file2)
10001093|234
10001093|40
10003251|4683
10003251|463005
10003252|46
10003260|468
23450986|123
1 Like

@Akshay: guess my awk wouldn't give the desired o/p :frowning:

following would give output but }!a[$1,$2]' is not good, it is more efficient to use var in array instead of array[var]

$ awk -F"|" 'FNR==NR{a[$1,$2]++;next}!a[$1,$2]' file1 file2
1 Like