Walt Mankowski via plug on 27 May 2021 17:29:47 -0700 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: [PLUG] Using diff |
I usually end up doing this in Perl or Python. The diff solution is nice. If you're interested, I've attached a little Perl script I just whipped up. It has the advantage of not requiring the lists to be sorted. Then I wrote a Python version, too. :) Walt On Thu, May 27, 2021 at 07:36:05PM -0400, Michael Lazin via plug wrote: > Awesome, thanks! Comm got the job done in a pinch but I am going to try > diff tomorrow morning. Thanks again for your help. > > Sincerely, > > Michael Lazin > > On Thu, May 27, 2021, 6:01 PM Carlos M. Fernández <aremmes@gmail.com> wrote: > > > This has worked for me before: > > > > diff -Nau first second | grep '^+' > > > > This assumes that first and second are sorted. > > > > On Thu, May 27, 2021, 17:37 Michael Lazin via plug < > > plug@lists.phillylinux.org> wrote: > > > >> I used the sort command to make two lists. One list has everything on > >> the first list and more. They are already alphabetically sorted. I want > >> to know what is on the second list that is not on the first list. I am > >> trying to use diff but perhaps there is a better way. I tried awk and an > >> ugly egrep and now I am giving up and asking for help. Thanks for your > >> time. > >> > >> Sincerely, > >> > >> Michael Lazin > >> > >> ___________________________________________________________________________ > >> Philadelphia Linux Users Group -- > >> http://www.phillylinux.org > >> Announcements - > >> http://lists.phillylinux.org/mailman/listinfo/plug-announce > >> General Discussion -- > >> http://lists.phillylinux.org/mailman/listinfo/plug > >> > > > ___________________________________________________________________________ > Philadelphia Linux Users Group -- http://www.phillylinux.org > Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce > General Discussion -- http://lists.phillylinux.org/mailman/listinfo/plug
#!/usr/bin/env perl use strict; use warnings; use autodie; my ($first, $second) = @ARGV; my $fh; open $fh, '<', $first; my %h = map {$_ => 1} <$fh>; open $fh, "<", $second; while (<$fh>) { print unless defined $h{$_}; }
#!/usr/bin/env python from sys import argv (first, second) = argv[1:] with open(first) as f: d = {line for line in f} with open(second) as f: for line in f: if line not in d: print(line, end='')
Attachment:
signature.asc
Description: PGP signature
___________________________________________________________________________ Philadelphia Linux Users Group -- http://www.phillylinux.org Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce General Discussion -- http://lists.phillylinux.org/mailman/listinfo/plug