- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: disk sorting
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
07-19-2002 09:42 AM
07-19-2002 09:42 AM
Suppose, I have the following disks:
c1t0d0
c2t0d0
c3t1d0
c4t0d0
c3t0d0
c1t0d2
c1t2d0
basic format is : cXtYdZ
and I want to sort using first X, then Y and then Z.
The following sort does a good job:
sort -t 'd' -k 1,2n -k1.1b,1.2b diskCollection
until, I have X as a double digit, e.g.
c11t6d0...
it puts c11t6d0 in front for reason.
Does anyone know how to force it for sort in a correct way?
Thank you!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2002 09:55 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2002 10:07 AM
07-19-2002 10:07 AM
Re: disk sorting
You could try to create the list with ll /dev/dsk/ sorted.
Later,
Bill
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2002 10:17 AM
07-19-2002 10:17 AM
Re: disk sorting
aahh,
Perhaps, ioscan could do it:
for i in $(ioscan -fnkC ext_bus | grep ext_bus | cut -d" " -f4)
> do
> ls /dev/dsk/c${i}t* | grep -v not
> done
on second thoughts, then there's the target to add in there in a second loop, it's easier to stick with Harry solution afterall!
Later,
Bill
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2002 10:21 AM
07-19-2002 10:21 AM
Re: disk sorting
I used this posix script recently.
#!/usr/bin/sh
ls -1 /dev/dsk | while IFS="ctd${IFS}" read ignore1 c t d ignore2
do
print $c $t $d
done | sort -n -k1n -k2n -k3n | while read c t d ignore
do
print c${c}t${t}d${d}
done
As you can see, I thorougly enjoy using the 'while read' method where possible.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2002 11:26 AM
07-19-2002 11:26 AM
Re: disk sorting
Your solution worked perfectly.
Unfortunately, I will have disk in the file in this kind of format, and the code you showed didn't actually work for this format.
c1t8d0 NONE 4095 JBOD/Other SEAGATE ST34573WC 0
c0t9d0 NONE 4095 JBOD/Other SEAGATE ST34573WC 1
c0t11d0 NONE 4095 JBOD/Other SEAGATE ST34573WC 2
do you know what is needed to be changed in your code?
Thank you very much!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2002 11:38 AM
07-19-2002 11:38 AM
Re: disk sorting
cat diskCollection | sed "s/^c\(.*\)t\(.*\)d\(\[0-9\]*\)/\1 \2 \3/" | sort -t" " -k1n -k2n -k3n|sed -e "s/^/c/" -e "s/ /t/" -e "s/ /d/"
This is by changes (.*) to ([0-9]*) means to scan only for numerics following the "d".
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2002 11:46 AM
07-19-2002 11:46 AM
Re: disk sorting
cc0t11d0tNONEd4095 JBOD/Other SEAGATE ST34573WC 2
cc0t9d0tNONEd4095 JBOD/Other SEAGATE ST34573WC 1
cc1t8d0tNONEd4095 JBOD/Other SEAGATE ST34573WC 0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2002 11:48 AM
07-19-2002 11:48 AM
Re: disk sorting
I tried your extended example and it still worked. Can you post what you used?
Also, using Rodney's modified because his drops the text, unless that's what you want, anyways here:
Oh wait, you do want to drop the text, correct? If so, use Rodney's. - I'm babnling, I think I need a drink SOON.
this keeps the text:
cat yank | sed "s/^c\(.*\)t\(.*\)d\([0-9]*\)\(.*\)/\1 \2 \3\4/" | sort -t" " -k1
n -k2n -k3n|sed -e "s/^/c/" -e "s/ /t/" -e "s/ /d/"
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2002 11:51 AM
07-19-2002 11:51 AM
Re: disk sorting
If you want to "drop" the text use this:
cat yank | sed "s/^c\(.*\)t\(.*\)d\([0-9]*\)\(.*\)/\1 \2 \3/" | sort -t" " -k1n
-k2n -k3n|sed -e "s/^/c/" -e "s/ /t/" -e "s/ /d/"
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2002 11:54 AM
07-19-2002 11:54 AM
Re: disk sorting
this is the file I used:
# cat yank
c1t8d0 NONE 4095 JBOD/Other SEAGATE ST34573WC 0
c0t9d0 NONE 4095 JBOD/Other SEAGATE ST34573WC 1
c0t11d0 NONE 4095 JBOD/Other SEAGATE ST34573WC 2
c1t0d0 NONE 4095 JBOD/Other SEAGATE ST34573WC 0
c1t10d0 NONE 4095 JBOD/Other SEAGATE ST34573WC 0
c1t10d1 NONE 4095 JBOD/Other SEAGATE ST34573WC 0
c1t10d5 NONE 4095 JBOD/Other SEAGATE ST34573WC 0
c11t6d0 NONE 4095 JBOD/Other SEAGATE ST34573WC 0
c1t10d30 NONE 4095 JBOD/Other SEAGATE ST34573WC 0
c2t0d0 NONE 4095 JBOD/Other SEAGATE ST34573WC 0
c3t1d0 NONE 4095 JBOD/Other SEAGATE ST34573WC 0
c4t0d0 NONE 4095 JBOD/Other SEAGATE ST34573WC 0
c3t0d0 NONE 4095 JBOD/Other SEAGATE ST34573WC 0
c1t0d2 NONE 4095 JBOD/Other SEAGATE ST34573WC 0
c1t2d0 NONE 4095 JBOD/Other SEAGATE ST34573WC 0
#
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2002 11:54 AM
07-19-2002 11:54 AM
Re: disk sorting
cat input | perl -p -e '/^c(\d+)t(\d+)d(\d+)/;$a=100+$1;$b=100+$2;$c=100+$3;s/^/$a$b$c\t/;' | sort -n | cut -f 2-
This will extract the 3 numerics, put them into a fixed format. The output will then be piped to sort and finally to cut to remove the sort key.
hope this helps...
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-19-2002 11:54 AM
07-19-2002 11:54 AM
Re: disk sorting
#!/usr/bin/sh
typeset -L9 DISK
while IFS="ctd${IFS}" read C T D RESTOFLINE
do
print $C $T $D "$RESTOFLINE"
done | sort -n -k1n -k2n -k3n | while read C T D REPLY
do
DISK="c${C}t${T}d${D}"
print "$DISK $REPLY"
done
Usage: cat YourFile | ./thisScript
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2002 09:55 AM
07-22-2002 09:55 AM
Re: disk sorting
Your script works perfectly.
Unfortunately, if I have alternate path disk instead of NONE, I get some screwed values:
e.g.
c1t8d0 c1t0d1 4095 JBOD/Other
c0t9d0 NONE 4095 JBOD/Other
Do you know how I can ignore the 2nd disk, and make it behave as was NONE?
Here is the script I used:
cat $TMPDIR/DiskSelection.$$ | sed "s/^c\(.*\)t\(.*\)d\(.*\)/\1 \2 \3/" | sort -t" " -k1n -k2n -k3n|sed -e "s/^/c/" -e "s/ /t/" -e "s/ /d/" >
Thanks a lot!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2002 07:14 AM
07-29-2002 07:14 AM
Re: disk sorting
change the "sed" to look for an "N" or a "c" in the second column:
sed "s/^c\(.*\)t\(.*\)d\(.*\) \([Nc].*\)/\1 \2 \3 \4/"
If you want to "drop" the text just omit the " \4"
live free or die
harry