LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 08-17-2007, 03:52 AM   #1
scbops
Member
 
Registered: Feb 2006
Posts: 97

Rep: Reputation: 15
gawk related issue


gawk related issue

ps aux |gawk ' { print $3,$2 }'

This command will print all the line, but I need to print first line only, anyone knows how to do that ?
 
Old 08-17-2007, 04:14 AM   #2
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
ps aux |gawk 'NR == 1 { print $3,$2 }'

if you really want the first line, which is the header. Another way is just with 'head -1', of course - or 'head -n1' as some versions now seem to require.
 
Old 08-17-2007, 04:15 AM   #3
slakmagik
Senior Member
 
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113

Rep: Reputation: Disabled
oops - LQ went squirelly for a bit - sorry for the double post

Last edited by slakmagik; 08-17-2007 at 04:16 AM. Reason: dupe
 
Old 08-17-2007, 05:56 AM   #4
scbops
Member
 
Registered: Feb 2006
Posts: 97

Original Poster
Rep: Reputation: 15
Thankd you very much look like big brain
Appreciate if you can tell this also how I can display the last line
 
Old 08-17-2007, 06:02 AM   #5
scbops
Member
 
Registered: Feb 2006
Posts: 97

Original Poster
Rep: Reputation: 15
Thankd you very much look like big brain
Appreciate if you can tell this also how I can display the last line
 
Old 08-17-2007, 10:14 AM   #6
schneidz
Senior Member
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-19-live-usb/ aix
Posts: 3,823

Rep: Reputation: 586Reputation: 586Reputation: 586Reputation: 586Reputation: 586Reputation: 586
i hope your not married to awk:

this is not elegant but it gets the job done:
Code:
ps aux |gawk '{ print $3,$2 }' | head -n 1; ps aux |gawk '{ print $3,$2 }' | tail -n 1
 
Old 08-17-2007, 10:45 AM   #7
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,695
Blog Entries: 5

Rep: Reputation: 240Reputation: 240Reputation: 240
well, theres no need to use so many pipes. you can get the header and last line using only 1 awk/gawk process.

Code:
ps aux |gawk 'NR==1{ print $3,$2 }{last=$3" "$2}END{print last}'
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Samba related issue......... rr_rr_29 Linux - Server 1 03-23-2007 12:36 AM
NFS related issue push19180 Linux - Networking 1 05-19-2006 07:36 AM
fc3 update related issue pirozzi Fedora 6 01-28-2005 12:24 PM
LTSP related issue emailssent Linux - Networking 1 12-12-2004 12:13 PM
process related issue LinuxRam Linux - Networking 1 09-12-2004 04:24 PM


All times are GMT -5. The time now is 08:34 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration