I have two files file1
and file2
, Both the files have 5 columns
.
I want to compare first 4 columns
of file1
with file2
.
If they are equal, need to compare the 5th column
. If 5th column values
are different, need to print the file1's 5th column
as file2's 6th column
.
I have used below awk
to compare two columns in two different files, but how to compare multiple columns and append the particular column in another file if matches found?
awk -F, 'NR==FNR{_1[$1]++;next}!_1[$1]'
file1:
111,item1,garde1,wing1,maingroup
123,item3,grade5,wing10,topcat
132,item2,grade3,wing7,middlecat
134,item2,grade3,wing7,middlecat
177,item8,gradeA,wing11,lowcat
file2:
111,item1,garde1,wing1,maingroup
123,item3,grade5,wing10,lowcat
132,item3,grade3,wing7,middlecat
126,item2,grade3,wing7,maingroup
177,item8,gradeA,wing11,lowcat
Desired output:
123,item3,grade5,wing10,lowcat,topcat
_1
would not qualify as such! – Ed Morton