Thread View: comp.unix.programmer
2 messages
2 total messages
Started by Steve Silberberg
Sun, 23 Aug 1998 00:00
Diff for text files whose paragraphs are out of order
Author: Steve Silberberg
Date: Sun, 23 Aug 1998 00:00
Date: Sun, 23 Aug 1998 00:00
47 lines
1698 bytes
1698 bytes
I am trying to write a program that will re-order a file so that the paragraphs are lined up. Then I can just run diff on the result. So for instance if I had 2 text files, each with 3 paragraphs: Text File 1 ----------------- abc 123 I am in cyberspace this is a text file Text File 2 ---------------- this is a text file abc 134 I am in cyberspace Output ------------- abc 134 I am in cyberspace this is a text file I'd like the program to reorder Text File 2 so I can then run the result through diff. I realize that if the two files are completely different, the output will look pretty wacky, but I'm not too worried abouyt that. Any ideas on how to write such a program? Does such a utility already exist? Many many thanks in advance. Steve ---------------- Steve Silberberg mailto:stevebo@onramp.net Visit the Air Sickness Bag Museum at: http://rampages.onramp.net/~stevebo/airsick.html FACT: Buff Babes Dig Cut Dudes!
Re: Diff for text files whose paragraphs are out of order
Author: 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}
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads