Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-11-2000 10:56 AM
тАО12-11-2000 10:56 AM
I am trying to sort the output of a given command. However, I wish to exclude the first 3 lines from the sort.
Is there an elegant way of doing this without going through the hassle of temporary files?
currently I use something like this:
my_app $* > /tmp/my_app.$$
head -2 /tmp/my_app.$$
sed -n '3,$p' /tmp/my_app.$$ | sort
rm /tmp/my_app.$$
I am wondering if there is something more elegant
Thanks,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-11-2000 11:07 AM
тАО12-11-2000 11:07 AM
Re: sorting
Try:
# my_app | awk 'NR > 3 {print $0}' | sort
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-11-2000 11:33 AM
тАО12-11-2000 11:33 AM
Re: sorting
I want to include in the output the top 3 lines. Your solution exlucdes the top lines from the output,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-11-2000 11:56 AM
тАО12-11-2000 11:56 AM
Re: sorting
# my_app | awk 'NR <= 3 {print $0}' >only_one_file
## my_app | awk 'NR > 3 {print $0}' | sort -o only_one_file
This way you have only one file created at any time.
Regards,
Madhu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-11-2000 01:28 PM
тАО12-11-2000 01:28 PM
SolutionOK, I assume you want to take the output of your process and sort it, but you do not want to include the first three lines of output in the sort -- as in the case of a table with a header. Therefore, consider this example:
Given a file that looks like:
1a
2b
3c
4c
5e
6f
7g
# cat my_file|awk '{if (NR <=3) {print $0} else {print $0|"sort -r"}}'
would produce output ordered:
1a
2b
3c
7g
6f
5e
4d
No temporary files would be used; the first three lines would pass "unsorted", and in this example (clearly) the remaining lines would be sorted (here in reverse).
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО12-11-2000 02:14 PM
тАО12-11-2000 02:14 PM
Re: sorting
That does solve my problem. I am just wondering how does awk pass the data to the sort command?