ShipWreck has asked for the wisdom of the Perl Monks concerning the following question:
Good morning Monks, I'm trying to do the bash equivalent of awk on a grep output of a linux process. The idea is to extract the process ID of an application running on the server. Code looks like this:
#!/usr/bin/perl @array = `ps -ef | grep kdfadm`; @A = grep (/\/opt\/kdf\/home/, @array); my @A = split; print $A[1];
Code output (shortened for readability):
[kdfadm@srv01 ~]$ /usr/bin/perl SplitTest kdfadm 121562 121527 0 Nov13 ? 00:01:15 /opt/kdf/home/jdk1.8 +.0_162/jre/bin/java -Xms512m -Xmx512m ... [kdfadm@srv01 ~]$
I've come to grasp that the output is essentially the first line, as opposed to the first field. How do I perform the equivalent of "awk {'print $1,$2,$8'}" in perl?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to awk a grep result in-script
by haukex (Archbishop) on Nov 14, 2019 at 18:29 UTC | |
|
Re: How to awk a grep result in-script
by hippo (Archbishop) on Nov 14, 2019 at 18:51 UTC | |
|
Re: How to awk a grep result in-script
by karlgoethebier (Abbot) on Nov 14, 2019 at 18:49 UTC | |
|
Re: How to awk a grep result in-script
by marioroy (Prior) on Nov 16, 2019 at 03:29 UTC | |
|
Re: How to awk a grep result in-script
by 1nickt (Canon) on Nov 15, 2019 at 14:30 UTC | |
|
Re: How to awk a grep result in-script
by ShipWreck (Initiate) on Nov 14, 2019 at 19:39 UTC | |
by AnomalousMonk (Archbishop) on Nov 15, 2019 at 00:21 UTC |