bash script for printing lines that don't match?
I think I've asked this in the past but try as I might I can't remember what the answer was or figure out how I solved it before. I have 2 files that are nearly identical and I need to know which lines in the two files do _not_ match. I can think of some relatively complex loops with grep etc. which would probably work (for every line in file A, grep in file B etc.) solve the problem but I'm hoping for something more elegant. I thought at first that perhaps "join" would do it but even though it will provide left and right joins, there is no way to prevent it from outputting the matching lines. Any ideas? John
Sounds like a job for diff(1). Use diff -u (I find it easier to read). There is also sdiff for 'side by side' visual comparison but I don't use that much. -- Sean (mobile) On 2012-09-18, at 12:13 PM, John Lange <john@johnlange.ca> wrote:
I think I've asked this in the past but try as I might I can't remember what the answer was or figure out how I solved it before.
I have 2 files that are nearly identical and I need to know which lines in the two files do _not_ match.
I can think of some relatively complex loops with grep etc. which would probably work (for every line in file A, grep in file B etc.) solve the problem but I'm hoping for something more elegant.
I thought at first that perhaps "join" would do it but even though it will provide left and right joins, there is no way to prevent it from outputting the matching lines.
Any ideas?
John _______________________________________________ Roundtable mailing list Roundtable@muug.mb.ca http://www.muug.mb.ca/mailman/listinfo/roundtable
For sorted data, there's also comm(1) which lets you pick any combination of file 1 only, file 2 only and/or common to both, in tabbed columns. On 18/09/2012 12:29 PM, Sean Cody wrote:
Sounds like a job for diff(1).
Use diff -u (I find it easier to read).
There is also sdiff for 'side by side' visual comparison but I don't use that much.
-- Gilles R. Detillieux E-mail: <grdetil@scrc.umanitoba.ca> Spinal Cord Research Centre WWW: http://www.scrc.umanitoba.ca/ Dept. Physiology, U. of Manitoba Winnipeg, MB R3E 0J9 (Canada)
diff(1)? Peter On 09/18/2012 12:13 PM, John Lange wrote:
I think I've asked this in the past but try as I might I can't remember what the answer was or figure out how I solved it before.
I have 2 files that are nearly identical and I need to know which lines in the two files do _not_ match.
I can think of some relatively complex loops with grep etc. which would probably work (for every line in file A, grep in file B etc.) solve the problem but I'm hoping for something more elegant.
I thought at first that perhaps "join" would do it but even though it will provide left and right joins, there is no way to prevent it from outputting the matching lines.
Any ideas?
John _______________________________________________ Roundtable mailing list Roundtable@muug.mb.ca http://www.muug.mb.ca/mailman/listinfo/roundtable
In case anyone knows someone interested in this West Jet TSA job ad http://t.co/D4iFxHpj On 18/09/12 17:35, Peter O'Gorman wrote:
diff(1)?
Peter
On 09/18/2012 12:13 PM, John Lange wrote:
I think I've asked this in the past but try as I might I can't remember what the answer was or figure out how I solved it before.
I have 2 files that are nearly identical and I need to know which lines in the two files do _not_ match.
I can think of some relatively complex loops with grep etc. which would probably work (for every line in file A, grep in file B etc.) solve the problem but I'm hoping for something more elegant.
I thought at first that perhaps "join" would do it but even though it will provide left and right joins, there is no way to prevent it from outputting the matching lines.
Any ideas?
John _______________________________________________ Roundtable mailing list Roundtable@muug.mb.ca http://www.muug.mb.ca/mailman/listinfo/roundtable
_______________________________________________ Roundtable mailing list Roundtable@muug.mb.ca http://www.muug.mb.ca/mailman/listinfo/roundtable
On 9/18/2012 12:54 PM, VE4PER/ Andy wrote:
In case anyone knows someone interested in this West Jet TSA job ad
Please refrain from posting job opportunities on the roundtable - we have a jobs list for that ( jobs@muug.mb.ca ). Also, this job is in Calgary. Rob
Hi, Not in bash, but awk: will show what is in file1 but not in file2 awk 'FNR == NR {arr[$0];next} !($1 in arr) {print}' file1 file2 I've used this to compare lists of rpms on our machines. -- Grigory Shamov HPC Analyst, Westgrid/Compute Canada E2-588 EITC Building, University of Manitoba (204) 474-9625 On 12-09-18 12:13 PM, "John Lange" <john@johnlange.ca> wrote:
I think I've asked this in the past but try as I might I can't remember what the answer was or figure out how I solved it before.
I have 2 files that are nearly identical and I need to know which lines in the two files do _not_ match.
I can think of some relatively complex loops with grep etc. which would probably work (for every line in file A, grep in file B etc.) solve the problem but I'm hoping for something more elegant.
I thought at first that perhaps "join" would do it but even though it will provide left and right joins, there is no way to prevent it from outputting the matching lines.
Any ideas?
John _______________________________________________ Roundtable mailing list Roundtable@muug.mb.ca http://www.muug.mb.ca/mailman/listinfo/roundtable
participants (7)
-
Gilles Detillieux -
Grigory Shamov -
John Lange -
Peter O'Gorman -
Robert Keizer -
Sean Cody -
VE4PER/ Andy