Merging two text files based on some kind of text anchors

T

triangle

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
 
G

Gunnar Hjalmarsson

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

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top