Merging two text files based on some kind of text anchors

Discussion in 'Perl Misc' started by triangle, Jan 30, 2004.

  1. triangle

    triangle Guest

    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
    triangle, Jan 30, 2004
    #1
    1. Advertising

  2. 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
    Gunnar Hjalmarsson, Jan 30, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stefan Franke

    merging two XML files

    Stefan Franke, Jan 4, 2005, in forum: XML
    Replies:
    5
    Views:
    766
    Joris Gillis
    Jan 4, 2005
  2. Replies:
    5
    Views:
    543
    Jerry Coffin
    Sep 24, 2006
  3. n o s p a m p l e a s e

    Merging two DLL files

    n o s p a m p l e a s e, Jun 18, 2007, in forum: C Programming
    Replies:
    10
    Views:
    1,256
    CBFalconer
    Jun 19, 2007
  4. Replies:
    8
    Views:
    183
  5. Vahid

    merging two files

    Vahid, Jun 5, 2007, in forum: Perl Misc
    Replies:
    2
    Views:
    114
    J. Gleixner
    Jun 5, 2007
Loading...

Share This Page