1827948 Members
3620 Online
109973 Solutions
New Discussion

Perl script extension

 
SOLVED
Go to solution
Chartier Jerome
Frequent Advisor

Perl script extension

Hi all,

I have a last question on the script provided by Hein below, http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=947337.
Is it possible to extract the pattern for all the file in a directory starting with ABC for example and store the result in one file?

$serial = shift @ARGV or die "please provide serial number to select on";
while (<>) {
if (/^flag_start/) {
$save = 1;
$file = 0;
undef @lines;
}
if (/^flag_stop/) {
$save = 0;
push @lines, $_;
if ($file) {
print while ($_ = shift @lines );
}
print "\n";
}
push @lines, $_ if $save;
$file++ if /$serial/;
}


Thanks in advance for your help

Best Regards

Jerome
J@Y
4 REPLIES 4
H.Merijn Brand (procura
Honored Contributor

Re: Perl script extension

I'm not sure if I understand the question, but I think you either need

a. glob ()
b. magic diamond
c. local @ARGV

a. my @files = glob "ABC*";
b. my @files = ; # space is important here
c. local @ARGV = ();

# perldoc -f glob
# man perlvar

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Muthukumar_5
Honored Contributor

Re: Perl script extension

Yes. You can,

Put this in a script file called,

#extrac.pl
$serial = shift @ARGV or die "please provide serial number to select on";
while (<>) {
if (/^flag_start/) {
$save = 1;
$file = 0;
undef @lines;
}
if (/^flag_stop/) {
$save = 0;
push @lines, $_;
if ($file) {
print while ($_ = shift @lines );
}
print "\n";
}
push @lines, $_ if $save;
$file++ if /$serial/;
}
# end #

# perl extract.pl ABC* > serial_no1.log

hth.
Easy to suggest when don't know about the problem!
Muthukumar_5
Honored Contributor
Solution

Re: Perl script extension

sorry. You have to give SerialKey too so,

# perl extract.pl ABC*

while (<>){} - will get data from all input files.

Example:

# perl extract.pl Serialkey1 ABC* > serialkey.tmp

There is another solution in this thread,
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=947337

hth.

Easy to suggest when don't know about the problem!
Chartier Jerome
Frequent Advisor

Re: Perl script extension

Many thanks to all of you ...

It is working now ... ;)

Jerome
J@Y