Merging two text files based on some kind of text anchors

From: triangle (david.knecht_at_anyweb.ch)
Date: 01/30/04


Date: 30 Jan 2004 11:57:41 -0800

Dear all,

I would like to merge two text files based on some criteria driven by
regular expressions.

Basically, this is what I'd like to achieve:

Contents of file 1:

abc
def
ghi

Contents of file 2 (defines the anchors and their contents):

[anchor1]This is some text for anchor 1.
[anchor2]This is some text for anchor 2.

The file which is the result of the merger process should look like
this:

abc This is some text for anchor 1.
def
ghi This is some text for anchor 2.

I'd like to define the anchors as regular expressions (identifying a
single line in file 1 or a range of multiple lines). Here, [anchor1]
is a regular expression which identifies the text "abc" in file 1.

Of course, "abc" might occur several times in file 1. To clearly
identify one particular instance of "abc" multiple identification
criteria might be required.

The basic idea is to merge comments in a fully automated manner to
some kind of source code, configuration file and the like.

I think of writing a Perl script for this but before doing that, I'd
like to check if there are other solutions/tools around. The plattform
is Linux.

If scripting it in Perl, are there any special Perl modules around for
this task?

Thanks, David



Relevant Pages

  • Re: PETER JENNINGS DEAD
    ... I have said before that Koppel would be a logical successor, but he doesn't seem to have any interest in staying at ABC, let alone anchoring the nightly news. ... I think you are correct that the network would be leery to pull Gibson out of GMA permanently, and that's what would have to happen if he was the nightly news guy. ... Vargas is younger, she can more than hold her own, and she would be the first woman to be the permananent solo anchor of a network nightly news, which would be CBS to the punch if they do land Couric next year. ...
    (rec.arts.tv)
  • Re: PETER JENNINGS DEAD
    ... > I will be curious to see what happens at ABC News now. ... Gibson seems to be ... > quite a good anchor in his own right, thought I don't know if ABC would want ... > interest in staying at ABC, let alone anchoring the nightly news. ...
    (rec.arts.tv)
  • Re: PETER JENNINGS DEAD
    ... I have said before that Koppel would be a logical successor, but he doesn't seem to have any interest in staying at ABC, let alone anchoring the nightly news. ... While it does seem cold to do so, I think ABC really has to think about a permanent replacement sooner rather than later. ... I think you are correct that the network would be leery to pull Gibson out of GMA permanently, and that's what would have to happen if he was the nightly news guy. ... Vargas is younger, she can more than hold her own, and she would be the first woman to be the permananent solo anchor of a network nightly news, which would be CBS to the punch if they do land Couric next year. ...
    (rec.arts.tv)
  • RE: returning hashes, and arrays
    ... They have a special meaning in the perl ... you're passing literals, not scalars to ... anchor(), but you're prototyping anchorto receive ... have done all my fun programming ideas in C, ...
    (perl.beginners)
  • Re: PETER JENNINGS DEAD
    ... ABC just finished airing a very loving tribute to him, ... Charlie Gibson anchored, and Ted Koppel, Barbara Walters, and Diane Sawyer ... quite a good anchor in his own right, thought I don't know if ABC would want ...
    (rec.arts.tv)