vineet2004 has asked for the wisdom of the Perl Monks concerning the following question:
the above lines are part of a file. the first 4 digits (or more) in each line make up the PID number(in this case there are 5 digits)...eg. 11403 the last column of each line has the file name. eg. su i need to find out PID number for the file name "hullBts_static"(in the above case it is 11408.......please mind that "hullBts_static" will not always be in the same line as shown... as the file entries change each time i run it).... then i need to generate a file name using the above found PID. this file name is of the form "frag_ PID.log"... in other words , the new filename will consist the matched PID. this file name will now have to be piped into a shell script file. my code looks like this....is it correct??11299 pts/4 00:00:00 su 11303 pts/4 00:00:00 bash 11403 tty2 00:00:00 bsc_static 11406 tty2 00:00:00 rtpTrau_static 11408 tty2 00:11:30 hullBts_static 11418 pts/4 00:00:00 tail 12157 pts/5 00:00:00 su
#!usr/bin/perl while(<>) { if(/^([\d]+)*(hullBts_static)/) { my $var1= "frag_$1.log"; } print STDOUT $var1; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Parsing 'ps' output
by polettix (Vicar) on Dec 28, 2006 at 11:35 UTC | |
|
Re: Parsing 'ps' output
by monarch (Priest) on Dec 28, 2006 at 11:26 UTC | |
|
Re: Parsing 'ps' output
by themage (Friar) on Dec 28, 2006 at 11:26 UTC | |
|