- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Sort column 4 in order ...
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
тАО02-27-2009 09:05 AM
тАО02-27-2009 09:05 AM
I want to sort the below using column 4:
ent0 Available 03-08 2-Port 10/100/1000 Base-TX PCI-X Adapter (14108902)
ent1 Available 03-09 2-Port 10/100/1000 Base-TX PCI-X Adapter (14108902)
ent2 Available 05-08 2-Port 10/100/1000 Base-TX PCI-X Adapter (14108902)
ent3 Available 05-09 2-Port 10/100/1000 Base-TX PCI-X Adapter (14108902)
ent4 Available Virtual I/O Ethernet Adapter (l-lan)
ent5 Available Virtual I/O Ethernet Adapter (l-lan)
ent6 Available Virtual I/O Ethernet Adapter (l-lan)
ent7 Available EtherChannel / IEEE 802.3ad Link Aggregation
ent8 Available Shared Ethernet Adapter
ent9 Available VLAN
ent11 Available EtherChannel / IEEE 802.3ad Link Aggregation
ent12 Available Shared Ethernet Adapter
ent13 Available VLAN
ent14 Available VLAN
and I need the output sorted in order:
2-Port
Virtual
EtherChannel
Shared
VLAN
Thanks very much for any help.
Chris.
Solved! Go to Solution.
- Tags:
- Sort
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-27-2009 09:13 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-27-2009 09:16 AM
тАО02-27-2009 09:16 AM
Re: Sort column 4 in order ...
Yes that works:
ent13 Available VLAN
ent14 Available VLAN
ent9 Available VLAN
ent0 Available 03-08 2-Port 10/100/1000 Base-TX PCI-X Adapter (14108902)
ent1 Available 03-09 2-Port 10/100/1000 Base-TX PCI-X Adapter (14108902)
ent2 Available 05-08 2-Port 10/100/1000 Base-TX PCI-X Adapter (14108902)
ent3 Available 05-09 2-Port 10/100/1000 Base-TX PCI-X Adapter (14108902)
ent11 Available EtherChannel / IEEE 802.3ad Link Aggregation
ent7 Available EtherChannel / IEEE 802.3ad Link Aggregation
ent12 Available Shared Ethernet Adapter
ent8 Available Shared Ethernet Adapter
ent4 Available Virtual I/O Ethernet Adapter (l-lan)
ent5 Available Virtual I/O Ethernet Adapter (l-lan)
ent6 Available Virtual I/O Ethernet Adapter (l-lan)
however I need the order to be:
ent0 Available 03-08 2-Port 10/100/1000 Base-TX PCI-X Adapter (14108902)
ent1 Available 03-09 2-Port 10/100/1000 Base-TX PCI-X Adapter (14108902)
ent2 Available 05-08 2-Port 10/100/1000 Base-TX PCI-X Adapter (14108902)
ent3 Available 05-09 2-Port 10/100/1000 Base-TX PCI-X Adapter (14108902)
ent4 Available Virtual I/O Ethernet Adapter (l-lan)
ent5 Available Virtual I/O Ethernet Adapter (l-lan)
ent6 Available Virtual I/O Ethernet Adapter (l-lan)
ent11 Available EtherChannel / IEEE 802.3ad Link Aggregation
ent7 Available EtherChannel / IEEE 802.3ad Link Aggregation
ent12 Available Shared Ethernet Adapter
ent8 Available Shared Ethernet Adapter
ent13 Available VLAN
ent14 Available VLAN
ent9 Available VLAN
....
A bit more tricky
Chris.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-27-2009 09:26 AM
тАО02-27-2009 09:26 AM
Re: Sort column 4 in order ...
you could sort it as noted above, then use grep to separate the components to individual files. the individual files would still be in sort order and could be "cat"ed back together in the order desired...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-27-2009 09:33 AM
тАО02-27-2009 09:33 AM
Re: Sort column 4 in order ...
Oh, you don't have equivalent fields either in number or "content". Therefore you need to reorder your fields; sort theml and reorder them again. Something along the lines of manufacturing an additional sort key (field) and them removing it after the sort also works. A partial solution:
# awk '{if (NF>3) {print $4,$0} else {print $3,$0}}' file|sort -k4,4|cut -d" " -f 1-
...you can play with this technique...
Regards!
...JRF...
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-27-2009 09:35 AM
тАО02-27-2009 09:35 AM
Re: Sort column 4 in order ...
You need to strip out your "sort field" information, append that to the beginning of each record, sort on field *ONE*, then strip off fields 2 thru last.
HP-Server-Literate since 1979
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-27-2009 11:33 AM
тАО02-27-2009 11:33 AM
Re: Sort column 4 in order ...
I'm back, having rushed to a meeting to do "real work". Sorry, I'm mixing 'awk' and Perl's notation of counting --- 'awk' and 'cut' from one and Perl from zero. This is simplisticly close to what you want:
# awk '{if (NF==9) {print $4,$0} else {print $3,$0}}' file|sort -k1,1|cut -d" " -f 2-
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-27-2009 12:24 PM
тАО02-27-2009 12:24 PM
Re: Sort column 4 in order ...
2-Port
Virtual
EtherChannel
Shared
VLAN"
which, as I stated earlier, isn't *sorted* either. Sorted order would be:
2-Port
EtherChannel
Shared
Virtual
VLAN
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-27-2009 12:45 PM
тАО02-27-2009 12:45 PM
Re: Sort column 4 in order ...
Still, if you want to sort something in you particular orders, which is non-alphabetic/numeric (as Old School points out) then YOU have to tell the system somehow what that order is.
For example, here is a conceptual solution in perl, ready for your refinement.
Actually... it may be all you need. It works for me :-).
-------------- tmp.pl -------------
my @order = qw ( 2-Port Virtual EtherChannel Shared VLAN ); # This defines the Order!
sub lawrenzo_special_sort {
# sort function called by perl with one line in $a
# and an other line to compare against in $b.
# empty for loop walking over pre-sorted order array and looking for the first match.
# On match, or at end, exit with loop count value in $a1
for ($a1 = 0; $a1<@order && !($a =~ /$order[$a1]/ ); $a1++) {}
# ditto for $b, setting up $b1
for ($b1 = 0; $b1<@order && !($b =~ /$order[$b1]/ ); $b1++) {}
# Now finesse the order by adding the number part of the entry to the priciple value.
$a1 += $1/100 if ($a =~ /^ent(\d+)/);
$b1 += $1/100 if ($b =~ /^ent(\d+)/);
#debug print "$a1\t$b1\t". substr($a, 0, 30) . ' | ' . substr($b, 0, 30) . "\n";
return ( $a1 <=> $b1 ); # return with comapred value.
}
# Action!
print sort {lawrenzo_special_sort} <>;
--------------------
Usage: # perl tmp.pl some-file
or: #some_command | perl tmp.pl
-----------------------------------------
ent0 Available 03-08 2-Port 10/100/1000 Base-TX PCI-X Adapter (14108902)
ent1 Available 03-09 2-Port 10/100/1000 Base-TX PCI-X Adapter (14108902)
ent2 Available 05-08 2-Port 10/100/1000 Base-TX PCI-X Adapter (14108902)
ent3 Available 05-09 2-Port 10/100/1000 Base-TX PCI-X Adapter (14108902)
ent4 Available Virtual I/O Ethernet Adapter (l-lan)
ent5 Available Virtual I/O Ethernet Adapter (l-lan)
ent6 Available Virtual I/O Ethernet Adapter (l-lan)
ent7 Available EtherChannel / IEEE 802.3ad Link Aggregation
ent11 Available EtherChannel / IEEE 802.3ad Link Aggregation
ent8 Available Shared Ethernet Adapter
ent12 Available Shared Ethernet Adapter
ent9 Available VLAN
ent13 Available VLAN
ent14 Available VLAN
Enjoy,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО02-27-2009 01:33 PM
тАО02-27-2009 01:33 PM
Re: Sort column 4 in order ...
Actually it would be: VLAN Virtual
Unless you used -d or -f.