I have two text files that I need to compare the contents of because one of them is missing 2 items that the other has, but I'm not sure which since they are long. I've tried diff and vimdiff with no luck. My files are both formatted like this in a jumbled order:
item1 item2 item3
item8 item10 item6
item32 item12 item7
How can I pick out which items one of text files has but the other lacks while ignoring the format and order?
Cyrus' example is by far shorter and more to the point, but thought I'd practice some (verbose)
awking ...Sample data:
Assumptions:
One possible
awksolution:RS="": set row separator (RS) to the empty string; this turns a file into one long recordNR==NFR: if this is the first (of two) files ...afile=FILENAME: save filename for later printingfor/a[$i]=1: use input fields 1-NF as indexes for associative arraya, setting array value to 1 (aka 'true')next: read next record, which in this case means read next fileNR!=FNR: if this is the second (of two) files ...bfileand associative arraybEND ...: process our arrays ...for (x in a): loop through the indexes of arrayaand assign to variablex, and if there's no comparable indexed entry in arrayb(! b[x]) then print a message about the array index (actually name of item from original file) missing frombfilefor (x in b): same as previous loop except checking for items inbfilebut not inafileThis
awkscript in action: