Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
to thisjones 11111 33334 09:37:46 awk jones 11113 44454 09:37:46 grep jones 11123 33334 09:37:46 /bin/ksh jones 11118 22234 06:18:58 -ksh
Here is how I did it with Unix:jones 11135 44322 09:39:38 grep jones 11118 22234 06:18:58 -ksh
Now my attempt to do it with perl shows this in my output file:ps -ef | grep Jones | awk '$8 !~ /awk/ && $8 !~ /\/bin\/ksh/ \ {print $1" "$2" "$3" "$5" "$8}'
I want this output (the same as I got in my unix script):jones 11111 55555 0 09:42:09 pts/1 0:00 /usr/local/bin/perl ps1 jones 22222 66666 0 09:42:09 pts/1 0:00 grep jones jones 33333 77777 0 09:42:09 pts/1 0:00 sh -c ps -ef | grep jones +> out r jones 44444 88888 0 06:18:58 pts/1 0:01 -ksh
Here is my attempt at it in Perl. Please advise how I can improve this so it works???jones 22222 66666 0 09:42:09 pts/1 0:00 grep jones jones 44444 88888 0 06:18:58 pts/1 0:01 -ksh
#!/usr/local/bin/perl system("ps -ef | grep Jones > outr"); $outr = 'outr'; open(OF, "$outr") || die "Can not open $outr: $!\n"; @data=(<OF>); close(OF); open(OF,">$outr") || die "File not opening $outr: $!\n"; foreach $_ (@data) { next if ($_ !~ m/\/usr/local/bin/perl ps1$/) && ($_ !~ /sh \-c ps \-ef + \| grep jones \> out) ; print OF $_; } close(OF);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Trying to grab process output.
by rob_au (Abbot) on Jul 16, 2002 at 14:10 UTC | |
|
Re: Trying to grab process output.
by Abigail-II (Bishop) on Jul 16, 2002 at 14:10 UTC | |
by Anonymous Monk on Jul 16, 2002 at 19:23 UTC | |
|
Re: Trying to grab process output.
by cybear (Monk) on Jul 16, 2002 at 14:11 UTC | |
|
Re: Trying to grab process output.
by thelenm (Vicar) on Jul 16, 2002 at 14:26 UTC |