Date: Tue, 01 Dec 2009 15:27:34 +0100 From: =?ISO-8859-1?Q?Micha=EBl_Gr=FCnewald?= <Michael.Grunewald@laposte.net> To: Peter Steele <psteele@maxiscale.com> Cc: "freebsd-questions@freebsd.org" <freebsd-questions@freebsd.org> Subject: Re: Sorting a device list Message-ID: <4B1527D6.3040008@laposte.net> In-Reply-To: <7B9397B189EB6E46A5EE7B4C8A4BB7CB33BBEAB5@MBX03.exg5.exghost.com> References: <7B9397B189EB6E46A5EE7B4C8A4BB7CB33BBEAB5@MBX03.exg5.exghost.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4B1527D6.3040008>