Results 1 to 5 of 5
hi, i want to know how can we use command 'head' and 'tail' work in a single statement to retrieve top n bottom line of a file.individually i know but ...
- 04-02-2010 #1Just Joined!
- Join Date
- Apr 2010
- Posts
- 0
hi i have joined this forum just now
hi, i want to know how can we use command 'head' and 'tail' work in a single statement to retrieve top n bottom line of a file.individually i know but how to do in a single command line.plz lets me now
- 04-02-2010 #2
hi and welcome.
The following is far from elegant and in fact downright ugly.
For more than occasional use, you might want to think about a shell wrapper, parameters, errorconditions and secure tmp file creation..head /var/log/messages > /tmp/tmp_file && tail /var/log/messages >> /tmp/tmp_file && cat /tmp/tmp_file && rm -f /tmp/tmp_fileYou must always face the curtain with a bow.
- 04-02-2010 #3
ah sorry, no need for a tmp file.
this will do:
Code:head /var/log/messages && tail /var/log/messages
You must always face the curtain with a bow.
- 04-02-2010 #4Just Joined!
- Join Date
- Apr 2010
- Posts
- 0
thanxs
actually i want to get process which uses maximum memory usage n minimum memory usage.
for maximum i used
ps -auxf | sort -nr -k 4 | head -1
it works n
tail -1 to get minimum
but instead of typing two lines can i do this in a single line.
- 04-02-2010 #5
You can try this:
The "pee" command is part of the moreutils package.Code:ps auxf | sort -nr -k 4|pee "head -1" "tail -1"
P.S.
The coffee lounge seems not the best place for questions like these.
It would have been better placed in Linux Applications.
Well, next time
Last edited by Irithori; 04-02-2010 at 02:47 PM.
You must always face the curtain with a bow.


Reply With Quote
