Article View: comp.unix.programmer
Article #3632Re: Diff for text files whose paragraphs are out of order
From: Thomas L|fgren
Date: Mon, 24 Aug 1998 00:00
Date: Mon, 24 Aug 1998 00:00
69 lines
3021 bytes
3021 bytes
>>>>> "Steve" == Steve Silberberg <stevebo@onramp.net> writes:
Steve> I am trying to write a program that will re-order a file so
Steve> that the paragraphs are lined up. Then I can just run diff
Steve> on the result.
Steve> So for instance if I had 2 text files, each with 3
Steve> paragraphs:
Steve> Text File 1
Steve> -----------------
Steve> abc 123
Steve> I am in cyberspace
Steve> this is a text file
Steve> Text File 2
Steve> ----------------
Steve> this is a text file
Steve> abc 134
Steve> I am in cyberspace
Steve> Output
Steve> -------------
Steve> abc 134
Steve> I am in cyberspace
Steve> this is a text file
Steve> I'd like the program to reorder Text File 2 so I can then
Steve> run the result through diff. I realize that if the two
Steve> files are completely different, the output will look pretty
Steve> wacky, but I'm not too worried abouyt that.
Steve> Any ideas on how to write such a program? Does such a
Steve> utility already exist? Many many thanks in advance.
First of all, this does certainly not belong in gnu.gcc.help (for help
on the Gnu C Compiler), so I've set the followups.
Don't know if this kind of program exists, but it should be fairly
straight-forward to write at least a quick-and-dirty version. I'm not
sure exactly what your criteria for the output would be, but from your
example it seeems like you would want the output to have the same
paragraph order as the first inpit file. Read in the files into some
kind of datastructure, like a linked list of paragraphs. Go through
the second linked list, and "sort" it after what the first list looks
like. This program will run in time proportional to the square of the
number of paragraphs, so if you're handling huge files with a lot of
paragraphs it might be slow, and you'll have to come up with something
better (sorting the lists might help a little).
Print out the results according to what the first input file looked
like.
Hth,
Tom
--
Wherever I lay my .emacs, that's my ${HOME}
Technical Details
Message-ID:
<x40lnoeac03.fsf@kobra.csd.uu.se>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<6rpg3f$qr0$1@news.onramp.net>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 11318c,7e538404d40fb750 X-Google-Attributes: gid11318c,public X-Google-Thread: f8c9b,7e538404d40fb750 X-Google-Attributes: gidf8c9b,public X-Google-Thread: fc89c,7e538404d40fb750 X-Google-Attributes: gidfc89c,public X-Google-Thread: 1012a6,7e538404d40fb750 X-Google-Attributes: gid1012a6,public From: Thomas L|fgren <d95thl@kobra.csd.uu.se> Subject: Re: Diff for text files whose paragraphs are out of order Date: 1998/08/24 Message-ID: <x40lnoeac03.fsf@kobra.csd.uu.se> X-Deja-AN: 384150123 References: <6rpg3f$qr0$1@news.onramp.net> Followup-To: comp.unix.programmer,comp.unix.questions,comp.unix.shell Organization: Computing Science Dep., University of Uppsala, Sweden. Newsgroups: comp.unix.programmer,comp.unix.questions,comp.unix.shell,gnu.gcc.help