Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can i preserve header info with this command 1

Status
Not open for further replies.
Feb 23, 2005
12
US
when i run this command ps gwv i get the output with header but if i grep from the resulting output i lose the header...pls what option can i use with grep to get the header ?

Thanks!

PID TTY STAT TIME PGIN SIZE RSS LIM TSIZ TRS %CPU %MEM COMMAND
0 - A 114:43 7 64 60 xx 0 0 0.0 0.0 swapper
1 - A 4:29 147 848 168 32768 25 36 0.0 0.0 /etc/ini
t
8196 - A 178820:41 0 48 40 xx 0 0 15.3 0.0 wait
12294 - A 182536:02 0 48 36 xx 0 0 15.6 0.0 wait
16392 - A 180015:28 0 48 40 xx 0 0 15.4 0.0 wait
20490 - A 183064:36 0 48 36 xx 0 0 15.6 0.0 wait
24588 - A 180567:19 0 48 36 xx 0 0 15.4 0.0 wait
28686 - A 184175:09 0 48 36 xx 0 0 15.7 0.0 wait
32784 - A 6:01 5 56 44 xx 0 0 0.0 0.0 reaper
36882 - A 3:15 1 92 32 xx 0 0 0.0 0.0 lrud
40980 - A 0:00 0 56 40 xx 0 0 0.0 0.0 xmfreed
45078 - A 0:00 0 56 36 xx 0 0 0.0 0.0 vmptacrt
49176 - A 0:20 13 72 60 xx 0 0 0.0 0.0 pilegc
 
[tt]grep[/tt] prints lines that match the pattern you specified. When the header doesn't match the pattern you specified, [tt]grep[/tt] won't print it. [tt]grep[/tt] doesn't know there's a "header"; it just knows there's some text.

So use [tt]head -n 1[/tt] to pull off the header first, then print the results of [tt]grep[/tt].
 
i tried this :

ps gwv | head -1 | grep wait

and it returned zero rows....?
 
chipperMDW stated [tt]head [red]-n[/red] 1[/tt]

[tt]ps gwv | head [red]-n[/red] 1 | grep wait[/tt]

Chacal, Inc.
 
This should work...
Code:
ps gwv | egrep "PID|wait"
Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top