Preserve first line and search in others

Hi gurus Is possible to preserve first line of text and search in another lines ?

the only way that I think is:

ps aux | awk '{if (NR==1) {print $0} else if ($11 ~ /sshd/) {print $0}}'

but is there any more elegant way ? thanks

More elegant? Dunno. Shorter? yes :wink:

ps aux | awk 'NR==1||$11~/sshd/'

Hi, I'm not sure if this is more elegant, but it's an alternative:

lakris@landet:~$ ps aux|head -1;ps aux|grep firefox|grep -v grep
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
lakris    2035 13.9 12.2 344128 125440 ?       Sl   16:42   0:47 /usr/lib/firefox-3.5.5/firefox -new-tab http://art.gnome.org/backgrounds/
lakris@landet:~$ 

Best regards,
Lakris

ps aux | egrep "^U|ssh[d]"
ps aux | sed '1p;/ssh[d]/!d'

---------- Post updated at 08:13 AM ---------- Previous update was at 08:04 AM ----------
Not the same format but..

ps -fC "sshd"

thanks :slight_smile:

ps aux | awk 'NR==1||$11~/sshd/'

is nice :slight_smile: