- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- How to sort fields of unequal lenght
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
Forums
Discussions
Discussions
Discussions
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
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
06-29-2006 03:31 AM
06-29-2006 03:31 AM
I have a file with source and destination ip@ and the traffic in bytes, delimited by ;
10.214.5.205;10.218.25.220;3568
10.214.4.235;10.217.25.26;250
10.214.3.2;10.216.25.26;1002506
10.214.3.20;10.219.25.200;4569870125
10.214.2.215;10.215.25.26;4024
10.214.1.205;10.214.25.26;10250
I want to sort on the traffic field to
see the top usages
I tried
cat test.sh | awk -F ";" {' print $3";"$2$1 '} | sort -k1,1
but that gives unsatisfactory output:
1002506;10.216.25.2610.214.3.2
10250;10.214.25.2610.214.1.205
250;10.217.25.2610.214.4.235
3568;10.218.25.22010.214.5.205
4024;10.215.25.2610.214.2.215
4569870125;10.219.25.20010.214.3.20
What we need to see is this:
4569870125;10.219.25.20010.214.3.20
1002506;10.216.25.2610.214.3.2
10250;10.214.25.2610.214.1.205
4024;10.215.25.2610.214.2.215
3568;10.218.25.22010.214.5.205
250;10.217.25.2610.214.4.235
I tried in perl with sort() but
it can't handle the field mappings.
So know I have run out of ideas
Thanks for your help
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2006 03:38 AM
06-29-2006 03:38 AM
Re: How to sort fields of unequal lenght
Add the '-n' switch to your sort:
# awk -F ";" {' print $3";"$2$1 '} /tmp/data |sort -kn1,1
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2006 04:01 AM
06-29-2006 04:01 AM
Re: How to sort fields of unequal lenght
I think it is best to add the field delimiter ';' and the numreic option:
awk -F';' '{print $3";"$2$1}' test.sh | sort -t';' -nrk1,1
mfG Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-29-2006 04:36 AM
06-29-2006 04:36 AM
Re: How to sort fields of unequal lenght
Yes, I agree with Peter, and I missed that. Add the field delimiter to the 'sort' too.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2006 07:56 PM
07-02-2006 07:56 PM
Re: How to sort fields of unequal lenght
Solution was so close and yet so far.
Anyone know how to do this in perl examples ??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-02-2006 08:02 PM
07-02-2006 08:02 PM
Solutionmy @sorted =
map { $_->[0] }
sort { $b->[9] <=> $a->[9] ||
$a->[1] <=> $b->[1] }
map { [ $_, split m/\D+/, $_ ] }
@unsorted;
Extend the sort to your content
Enjoy, Ha ve FUN! H.Merijn