I have to compare two .csv files which having 4 columns and i am expecting the output if there is difference in the 3,4columns in two files with respect to the first column. if my statement is not clear please refer the example.
Input:
-----
File 1 :
hostname MAC SWITCH_IP SWITCH_PORT
01HW1234 000 172.20.1.1 Fastethernet1
Note: the comparision is performing with respect to 1st column(hostname).If there is any changes in SWITCH_IP and SWITCH_PORT then it wil display all the values in the file 2.
$ nawk 'NR==FNR{a[$1]=$0;next}($1 in a) {print}' f1 f2
hostname MAC SWITCH_IP SWITCH_PORT
01HW1234 000 172.20.1.1 Fastethernet1
01HW1234 000 172.20.1.0 Fastethernet2
---> also display unchanged lines
$ nawk 'NR==1{print}NR==FNR{a[$1]=$0;next}($1 in a)&&$0!=a[$1]' f1 f2
hostname MAC SWITCH_IP SWITCH_PORT
01HW1234 000 172.20.1.1 Fastethernet1
--->does not display unchanged lines (except the header line of course)
---------- Post updated at 03:53 PM ---------- Previous update was at 03:37 PM ----------
or more simply
nawk 'NR==FNR{a[$1]=$3$4;next}($1 in a)&&($3$4!=a[$1])||FNR==1' file1 file2