I have already explained about how to lookup in flat file using AWK in earlier post, for more detail/explain follow How To Look-Up in File Data Using AWK
Input Data : F_Data_File1.txt
EMPID
10001
10002
10003
10004
10008
Input Data : F_Data_File2.txt
EMPID|ENAME|DEPT
10001|A1|TRANS
10002|A2|MED
10003|A3|FIN
10004|A4|HR
10005|A5|CSR
10006|A6|TRANS
10007|A7|FIN
10008|A8|HR
Desired Output: We need to fetch the deails of the records which are not available in F_Data_File1.txt from file F_Data_File2.txt
EMPID|ENAME|DEPT
10005|A5|CSR
10006|A6|TRANS
10007|A7|FIN
Solution:
$ awk 'NR==FNR && FNR !=1 {A[$1];next} !($1 in A)' FS="|" F_Data_File1.txt F_Data_File2.txt
Input Data : F_Data_File1.txt
EMPID
10001
10002
10003
10004
10008
Input Data : F_Data_File2.txt
EMPID|ENAME|DEPT
10001|A1|TRANS
10002|A2|MED
10003|A3|FIN
10004|A4|HR
10005|A5|CSR
10006|A6|TRANS
10007|A7|FIN
10008|A8|HR
Desired Output: We need to fetch the deails of the records which are not available in F_Data_File1.txt from file F_Data_File2.txt
EMPID|ENAME|DEPT
10005|A5|CSR
10006|A6|TRANS
10007|A7|FIN
Solution:
$ awk 'NR==FNR && FNR !=1 {A[$1];next} !($1 in A)' FS="|" F_Data_File1.txt F_Data_File2.txt
No comments:
Post a Comment