Operating System - HP-UX
1748022 Members
5332 Online
108757 Solutions
New Discussion

Re: Perl equivalent needed

 
SOLVED
Go to solution
Allanm
Super Advisor

Re: Perl equivalent needed

Tried $_ but I am not getting what I want.

Thanks,
Allan.
Hein van den Heuvel
Honored Contributor

Re: Perl equivalent needed


Hmmm, not sure exactly what you want, and not sure what you tried with $_ but maybe this helps?

To attach all the original message lines you basically have 2 choices.

1) stash them all in an array as you process, then print that array after printing the headlines.

2) after gathering and printing the headlines, re-read the source and print to log

1)

while() {
push @everything, $_;
chomp;
$app = $1 if /Appname:(.*)/;
$host = $1 if /^Host:(.*)/;
if (/Date\/Time:(.*)/) { printf FW "%s:%s:%s\n",$app,$host,$1; }
}
print FW @everything;
$cmd='mail ...



2)

while() {
chomp;
$app = $1 if /Appname:(.*)/;
$host = $1 if /^Host:(.*)/;
if (/Date\/Time:(.*)/) { printf FW "%s:%s:%s\n",$app,$host,$1; }
}
seek FH,0,0; # back to the beginning
print FW ; # dump it all

$cmd='mail...



my tests....
# cat x.txt
aap
test: xxx
noot
test: yyy
mies

1) # perl -e "open X,qq() {push @everything,$_; print if /test/} print @everything"

2) # perl -e 'open X,qq() {print if /test/}; seek X,0,0; print '

both giving:
test: xxx
test: yyy
aap
test: xxx
noot
test: yyy
mies


Good luck!
Hein