From owner-freebsd-questions@FreeBSD.ORG Tue Dec 1 14:57:22 2009 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id D0D031065672 for ; Tue, 1 Dec 2009 14:57:22 +0000 (UTC) (envelope-from Michael.Grunewald@laposte.net) Received: from mx2.mpim-bonn.mpg.de (mx2.mpim-bonn.mpg.de [195.37.209.170]) by mx1.freebsd.org (Postfix) with ESMTP id 657328FC0A for ; Tue, 1 Dec 2009 14:57:22 +0000 (UTC) X-IronPort-AV: E=McAfee;i="5400,1158,5818"; a="423278" X-IronPort-AV: E=Sophos;i="4.47,321,1257116400"; d="scan'208";a="423278" Received: from mailout.mpim-bonn.mpg.de (HELO ismene.mpim-bonn.mpg.de) ([192.168.42.38]) by mx2.mpim-bonn.mpg.de with ESMTP; 01 Dec 2009 15:27:37 +0100 Received: from [192.68.254.5] (pallas.mpim-bonn.mpg.de [192.68.254.5]) by ismene.mpim-bonn.mpg.de (8.13.8/8.13.8) with ESMTP id nB1ERZXa005793; Tue, 1 Dec 2009 15:27:36 +0100 (CET) Message-ID: <4B1527D6.3040008@laposte.net> Date: Tue, 01 Dec 2009 15:27:34 +0100 From: =?ISO-8859-1?Q?Micha=EBl_Gr=FCnewald?= User-Agent: Mozilla/5.0 (X11; U; SunOS sun4v; en-US; rv:1.7.12) Gecko/20050928 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Peter Steele References: <7B9397B189EB6E46A5EE7B4C8A4BB7CB33BBEAB5@MBX03.exg5.exghost.com> In-Reply-To: <7B9397B189EB6E46A5EE7B4C8A4BB7CB33BBEAB5@MBX03.exg5.exghost.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Cc: "freebsd-questions@freebsd.org" Subject: Re: Sorting a device list X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 01 Dec 2009 14:57:22 -0000 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