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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
08-17-2007, 03:52 AM
|
#1
|
|
Member
Registered: Feb 2006
Posts: 97
Rep:
|
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 ?
|
|
|
|
08-17-2007, 04:14 AM
|
#2
|
|
Senior Member
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113
Rep: 
|
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.
|
|
|
|
08-17-2007, 04:15 AM
|
#3
|
|
Senior Member
Registered: Feb 2003
Distribution: Slackware
Posts: 4,113
Rep: 
|
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
|
|
|
|
08-17-2007, 05:56 AM
|
#4
|
|
Member
Registered: Feb 2006
Posts: 97
Original Poster
Rep:
|
Thankd you very much look like big brain
Appreciate if you can tell this also how I can display the last line
|
|
|
|
08-17-2007, 06:02 AM
|
#5
|
|
Member
Registered: Feb 2006
Posts: 97
Original Poster
Rep:
|
Thankd you very much look like big brain
Appreciate if you can tell this also how I can display the last line
|
|
|
|
08-17-2007, 10:14 AM
|
#6
|
|
Senior Member
Registered: May 2005
Location: boston, usa
Distribution: fc-12/ fc-11-live-usb/ aix
Posts: 2,674
|
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
|
|
|
|
08-17-2007, 10:45 AM
|
#7
|
|
Senior Member
Registered: Aug 2006
Posts: 2,695
|
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}'
|
|
|
|
| Thread Tools |
Search 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
HTML code is Off
|
|
|
All times are GMT -5. The time now is 05:59 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|