Fred Stluka via plug on 1 Jun 2021 17:10:53 -0700 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: [PLUG] Using diff |
Walt, Yeah, loading a dictionary in Python is a great 1st step towards lots of useful stuff. A client of mine had a catastrophe once. A programmer allowed cascaded deletes on a database. So when an employee left and got deleted from the DB, all her patients got deleted also, and all of their donations, disbursements, pictures, guestbook entries, etc. A major chuck of the DB was gone. Fortunately, we had good backups. But hours had passed with lots of valid donations to other patients and other DB changes by users around the world. We couldn't afford to restore from backup. Instead we froze the system, and did a dump of the new and old DBs as text files containing INSERT statements. Used an approach like yours to load all the INSERT statements into new and old Python dictionaries, then looped through them, generating a new dump file with exactly the right INSERT statements to recreate all the original data, plus all of the desired changes, but not the accidental changes. Re-created the DB from that dump file and came back on-line. Total downtime was minimal. Good stuff! --Fred ------------------------------------------------------------------------ Fred Stluka -- http://bristle.com -- Glad to be of service! Open Source: Without walls and fences, we need no Windows or Gates. ------------------------------------------------------------------------ On 5/27/21 9:06 PM, Walt Mankowski via plug wrote:
I didn't know about the -u option to uniq. Nice! I think the reason I tend to do them in Perl or Python is that it's usually part of a bigger process and I want to do some sort of post-processing on the list. The pattern of reading the first file into a dictionary, then checking the contents of the second file against the dictionary, is useful for all sorts of things. On Thu, May 27, 2021 at 08:53:08PM -0400, Martin Dellwo via plug wrote:If you know one list contains the other entirely, and neither has its own repetitions, ‘sort first second | uniq -u’ oughta work just fine. Martin Dellwo martin.dellwo@gmail.comOn May 27, 2021, at 8:29 PM, Walt Mankowski via plug <plug@lists.phillylinux.org> wrote: 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. :) WaltOn 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 LazinOn 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<not_in_first.pl> <not_in_first.py> ___________________________________________________________________________ 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___________________________________________________________________________ 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