[lug] perl/awk question
Chip Atkinson
chip at rmpg.org
Thu May 18 18:17:43 MDT 2000
Here's something you might find useful for the same thing:
#!/usr/bin/perl
@psarr = `ps -ef`;
foreach $psline (@psarr)
{
if ($psline =~ /sendmail/ && $psline !~ /$0/)
{
@pidarr = split (/ +/, $psline);
print ("$pidarr[5]\n");
}
}
Chip
On Thu, 18 May 2000, arnie wrote:
> I have a perl script where I need to extract a particular field from the output
> of ps. At the command line, if I issue the command:
>
> ps -ef | grep arnie | grep -v grep | awk '{print $6}'
>
> I get the expected results, in this case all of the contents of the sixth
> fields from ps. However, if I try to do this in perl like this:
>
> @grep_array = `ps -ef | grep arnie | grep -v grep | awk '{print $6}'`;
> print @grep_array;
>
> then the output is all of the fields returned from ps, as if the awk is never
> executed. I have tried escaping the ticks and curly braces, but it didn't
> work. How can I correct this so I get only the specified field(s) into my
> array?
>
> thanks,
> --
> arnie sherman
> frenomulax at bigfoot.com
>
> "I'm only Bob Dylan when I have to be."
> - Bob Dylan
>
>
> _______________________________________________
> Web Page: http://lug.boulder.co.us
> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug
>
More information about the LUG
mailing list