The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
grep unix.com with google



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Reply
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-14-2009
Registered User
 

Join Date: Jul 2009
Posts: 36
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:


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

but is there any more elegant way ? thanks
  #2 (permalink)  
Old 11-14-2009
Registered User
 

Join Date: Nov 2008
Location: Amsterdam
Posts: 1,258
More elegant? Dunno. Shorter? yes

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

  #3 (permalink)  
Old 11-14-2009
Registered User
 

Join Date: Oct 2007
Location: Stockholm
Posts: 264
Quote:
Originally Posted by wakatana View Post
Hi gurus Is possible to preserve first line of text and search in another lines ?
Hi, I'm not sure if this is more elegant, but it's an alternative:


Code:
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
  #4 (permalink)  
Old 11-14-2009
Registered User
 

Join Date: Nov 2008
Location: Amsterdam
Posts: 1,258

Code:
ps aux | egrep "^U|ssh[d]"


Code:
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..

Code:
ps -fC "sshd"


Last edited by Scrutinizer; 11-14-2009 at 12:21 PM..
  #5 (permalink)  
Old 11-14-2009
Registered User
 

Join Date: Jul 2009
Posts: 36
thanks

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

is nice
Sponsored Links
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Search a line and output next line as well kamranjalal Shell Programming and Scripting 10 12-29-2008 10:59 PM
Perl script to search a line and copy it to another line ammu Shell Programming and Scripting 3 12-29-2008 05:12 PM
search for a string ,replace the whole line with new line kkraja Shell Programming and Scripting 4 08-07-2008 03:26 AM
query on how to search for a line and read 4th word from that line jaggesh UNIX for Dummies Questions & Answers 4 07-01-2008 11:21 PM
Perl: Search for string on line then search and replace text Crypto Shell Programming and Scripting 4 01-04-2008 10:24 AM



All times are GMT -4. The time now is 09:19 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0