Hi guys,

I am looking for such a perl program that matches a pattern in file and print all remaining lines below the pattern.

for example.

If i have a file like..

Column1 Column2

ABC DEF
GHI KJL
ADG MKO
HGI KIO
HFO PIL


This is a my pattern

Groupname GroupLabel Id
ABC Function 123
DER Fucntion1 478

------------------------------

Now i want to print all the lines after 'This is a my pattern' keyword i.e.,

Groupname GroupLabel Id
ABC Function 123
DER Fucntion1 478


Please help me out

Thanks in advance

Hi singhabsk,

Thanks for your response

i have tried to get my desired output by using tr function but it is replacing all the characters with defined string incluing my desired output also except a one patter string and it is only displaying me a pattern string which i have taken as a varibale i want to match each line of a file with a pattern and if a pattern matches then display me all the pattern string and all the lines below pattern i don't want any line above pattern line

please help me out on this

Thanks

Hello Guys,

Atlast i have done it here is the code.

#!/usr/bin/perl -w
use strict;
use warnings;

my $InputFileName = 'C://New Folder//Data_File.txt';
my $OutputFileName = 'C://New Folder//Data_All_File.txt';
my $string = 'My pattern Analysis';
my $strLine;
my $a = 0;
my $new_count;
my $new_arr;

die "Usage: $0 <inputfile_name> <outputfile_name> <string>\n" unless ($InputFileName and $OutputFileName and $string);
open(IN,"<$InputFileName") or die "Could not open input: $!\n";
open(OUT,">$OutputFileName") or die "Could not open output: $!\n";

while(<IN>) 
{
$strLine = $_;
#print $strLine;
if ($strLine =~ /$string/)
{
#next;
$new_count = $a;
my @new_arr = <IN>;
print OUT @new_arr;

}
$a++;
}

good :)
but its too long
best of luck

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.