Hello All;
I have two files with below conditions:
- Entries in file A is missing in file B (primary is field 1)
- Entries in file B is missing in file A (primary is field 1)
- Field 1 is present in both files but Field 2 is different.
Example Content:
File A
531520011,8501,20160831000000,20160931000000
531520012,8502,20160831000001,20160931000001
531520013,8503,20160831000002,20160931000002
531520014,8504,20160831000003,20160931000003
531520017,8505,20160831000006,20160931000006
531520018,8015,20160831000007,20160931000007
531520019,8015,20160831000008,20160931000008
531520020,8015,20160831000009,20160931000009
531521020,8010,20160831000009,20160931000009
531520021,8015,20160831000010,20160931000010
File B
531520011,8511,20160831000000,20160931000000
531520012,8512,20160831000001,20160931000001
531520013,8513,20160831000002,20160931000002
531520018,8015,20160831000007,20160931000007
531522019,8015,20160831000008,20160931000008
531522020,8015,20160831000009,20160931000009
531521020,8010,20160831000009,20160931000009
531522021,8015,20160831000010,20160931000010
For Condition 1, I used the below code:
- Entries in file A is missing in file B (primary is field 1)
awk -F"," 'FNR==NR{A[$1]=$1;next} !($1 in A){print $0}' FileA File B
Similarly, For Condition 2, I used the below code:
2. Entries in file B is missing in file A (primary is field 1)
awk -F"," 'FNR==NR{A[$1]=$1;next} !($1 in A){print $0}' FileB File A
But for the third condition, I am facing issue.
3. Field 1 is present in both files but Field 2 is different.
I am using below code which is not working:
awk -F, 'NR==FNR{a[$2]=$1$2;next } !(a[$2]==$1$2){print $0}' FileA File B
I know that am missing a part of the logic to handle the missing entries. Please assist on the Condition 3.:wall:
## Just to add, I need to print the changed entry of file 1 and file2 (condition 3) both - in two different output files. I can do it using awk and comm - but I am looking for a single command to do this.