in reply to Re: Search and Replace for XML
in thread Search and Replace for XML

Hai Narveson,

Thank you for considering me, let me tell you straight, There are two file a.txt and b.txt, i want each line of text in a.txt should be searched, if searched text found in b.txt then it has to replace with a newline along with the searched text, i hope so this will be clear to you.

Regards,

Sriram

Replies are listed 'Best First'.
Re^3: Search and Replace for XML
by GrandFather (Saint) on Apr 29, 2008 at 04:37 UTC

    How about you show us a very small sample data set and the code you are having trouble with along with the output you get and the output you expect.

    Note that for small samples it is convenient to use strings as the input files and to print output. Consider:

    use strict; use warnings; my $fileA = <<FILEA; Thank you for considering me. Let me tell you straight, there are two file a.txt and b.txt. I want each line of text in a.txt should be searched FILEA my $fileB = <<FILEB; txt FILEB my @words; open my $bIn, '<', \$fileB or die "Open fileB failed: $!"; while (<$bIn>) { chomp; push @words, $_; } close $bIn; my $match = join '|', @words; open my $aIn, '<', \$fileA or die "Open fileA failed: $!"; while (<$aIn>) { next unless /\b($match)\b/; print; } close $aIn;

    Prints:

    Let me tell you straight, there are two file a.txt and b.txt. I want each line of text in a.txt should be searched

    which reads a "file" containing a list of words - one per line, then prints lines from a second "file" that contain any word from the list. Not the job you want to do I know, but I can't yet tell what it is that you do want to do!


    Perl is environmentally friendly - it saves trees
Re^3: Search and Replace for XML
by srprabu (Initiate) on Apr 29, 2008 at 04:28 UTC

    Hai Narveson,

    Sorry Narveson, as i am new to this forum by absently i posted my reply in the comments, i am extremely sorry!

    Thank you for considering me, let me tell you straight, There are two file a.txt and b.txt, i want each line of text in a.txt should be searched, if searched text found in b.txt then it has to replace with a newline along with the searched text, i hope so this will be clear to you.

    Regards,

    srprabu