f



Merging two text files based on some kind of text anchors

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
0
david
1/30/2004 7:57:41 PM
comp.lang.perl.misc 33233 articles. 2 followers. brian (1246) is leader. Post Follow

1 Replies
647 Views

Similar Articles

[PageSpeed] 57

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

<snip>

> 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.

Don't think this is the best place to ask for other solutions, but I
can tell you that Perl is sufficient.

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

Don't know. But it's not exactly rocket science, so why not just go
for it?

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

0
Gunnar
1/30/2004 9:00:52 PM
Reply: