how to select a line using awk
Hi,
I wish to know how to select a line using awk. when I do "`ps -ax | grep "pattern" | awk {'print $5'}`" it gives me following output /pattern /pattern /pattern /pattern /pattern I want to select first line of above output for some comparision. Please help me to solve the above problem. |
have a look at `head' (-n 1)
|
Quote:
Code:
ps ax | grep "pattern" | awk '{ print $5 }' | head -n 1 EDIT: sorry, just realized that a reply had already been posted... sometimes i forget to refresh the tabs before posting... |
Or just for fun if you just wanna use awk:
Code:
ps ax | awk '/pattern/ {if (p == "") {p = $5}} END {print p}' |
Another one
Code:
ps auxwwf | awk '/pattern/ {print $5; exit;}' |
Darn nx5000, yours is more elegant than mine.
But mine is less comprehensible :) jlinkels |
All times are GMT -5. The time now is 11:05 AM. |