Peter Steele wrote:

Can anyone recommend a quick and dirty way to sort a device list? For example, 
if I do this:
I need to skip the device prefix before applying the -g option. Something like 
this works:

ls /dev/ad*|sort -g -k 1.8

/dev/ad4
/dev/ad6
/dev/ad8
/dev/ad10

but this assumes the device name is just two characters long. I want a quick 
way to sort a generic device list like this, considering only the numeric part 
of the device for the key. Is there a quick and dirty way to do this or do I 
need to pipe it into a perl script or something?

You can use sed to insert a sepcial character before the first digit, use sort with this special character as field delimiter, and then remove the special character with another call to sed. The following pipeline does it:

sed -e 's/\([0-9]\)/@\1/' | sort -t @ -n -k 2 | sed -e 's/@//'

(This assumes `@' does not appear in the names of the devices you are working with.)

Hope this helps!
--
Michaël

_______________________________________________
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"

Reply via email to