I get the following message when I do a "ps -ef | grep port"
apache 6215 1 0 11:20 ? 00:00:00 perl /scripts/myscript.pl -sn 4123E -sku HSME01-HW -port 8
Is there a way to parse the following:
Using Grep to Filter the Output of a CommandA command's output can be filtered with grep through piping, and only the lines matching a given pattern will be printed on the terminal. You can also chain multiple pipes in on command. As you can see in the output above there is also a line containing the grep process.
* has a special meaning both as a shell globbing character ("wildcard") and as a regular expression metacharacter. You must take both into account, though if you quote your regular expression then you can prevent the shell from treating it specially and ensure that it passes it unchanged to grep .
You can use awk
for both filtering and parsing:
ps -ef | awk '/[p]ort/ {printf "start time: %s\nsn: %s\nsku: %s\nport: %s\n", $5, $11, $13, $NF}'
As glenn jackman pointed out in the comments the square brackets in the filter string prevent the expression from matching the filter string itself in the process list.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With