Operating System - HP-UX
1829615 Members
2011 Online
109992 Solutions
New Discussion

Re: Can someone help me parse this file?

 
SOLVED
Go to solution
Hein van den Heuvel
Honored Contributor

Re: Can someone help me parse this file?



Here is what I tend to use:

$file = shift @ARGV or die "Please provide parameter file name argument"


This takes the first argumentafter the perl program away from the ARGV array and sticks it in $file.

So if you had a second argument, maybe some counter, then you can repeat that and the next line could be:

$counter = shift @ARGV or die "Please provide counter value as argument"



In a simple one-liner which will 'cat' a file:

perl -e '$file=shift @ARGV or die "Please provide parameter file name argument"; open (X,$file) or die "open problem $file"; print while ()' x

And a second argument can turn it into a 'head' function:

perl -e '$file=shift @ARGV || die "file name?"; $count=shift @ARGV || die "counter?"; open (X,$file) or die "open $file ?"; while (){last if ($i++ > $count); print}' x 3

Hein.





MAD_2
Super Advisor

Re: Can someone help me parse this file?

I don't understand...

How do you integrate that in comparsion to the command initially provided?

ps -fu | perl tux.p

The tux.p perl program would contain in instead what for the first 3 lines that were originally provided?

$file = "";
$format = "%15s |%10s |%4s |%4s |%4s |%4s |%s\n";
open (TUX,"<$file") or die "Could not open $file";

Thanks!

MAD

Contrary to popular belief, Unix is user friendly. It's just very particular about who it makes friends with
Hein van den Heuvel
Honored Contributor

Re: Can someone help me parse this file?


Old line with hard-coded file name:
$file = "";

To be replaced with new line:
$file = shift @ARGV or die "Please provide parameter file name argument"

That's all.

Hein.
Sandman!
Honored Contributor

Re: Can someone help me parse this file?

Adam,

I was out for a few days so couldn't work on the script. I have finished it now and its attached "wrapper.ksh". The awk parser script "parse.awk" called from within the wrapper is pasted below. Just run the wrapper script on the command line as follows:

# wrapper.ksh

Let me know if you run into problems and i'll be happy to tweak it.

cheers!!!


===============parse.awk=====================

# strops function
function strops(input, words, n)
{
n = split(input, words, "=")
return words[n]
}

# main routine
BEGIN {
RS=""; OFS="|"
} /^service/ {
print $1,
strops($2),
strops($3),
strops($4),
strops($5)
}
=============================================