Re: Sorting a device list

2009-12-01 Thread Michaël Grünewald

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


Re: Sorting a device list

2009-11-29 Thread Oliver Mahmoudi
you can try to delete the /dev/ad10 entry with sed and then just append it
to the end manually using the
printf(1) utility like so:

# ls /dev/ad* | sed s/\/dev\/ad10// | grep /dev/ad  printf
/dev/ad10\n

Does that help?

Oliver





On Sun, Nov 29, 2009 at 6:56 AM, Peter Steele pste...@maxiscale.com wrote:

 I had tried that. It doesn't work:

 # ls -d1 /dev/ad* | sort -n
 /dev/ad10
 /dev/ad4
 /dev/ad6
 /dev/ad8

 I want the ad10 to appear last...

 -Original Message-
 From: Giorgos Keramidas [mailto:keram...@ceid.upatras.gr]
 Sent: Saturday, November 28, 2009 4:31 PM
 To: Peter Steele
 Cc: freebsd-questions@freebsd.org
 Subject: Re: Sorting a device list

 On Sat, 28 Nov 2009 11:48:18 -0600, Peter Steele pste...@maxiscale.com
 wrote:
  Can anyone recommend a quick and dirty way to sort a device list? For
 example, if I do this:
 
  ls /dev/ad* | sort
 
  I get something like this:
 
  /dev/ad10
  /dev/ad4
  /dev/ad6
  /dev/ad8

 Just use `sort -n':

ls -d1 /dev/ad* | sort -n

 It should work fine even when there are non-numeric prefix strings.


 ___
 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

___
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


RE: Sorting a device list

2009-11-29 Thread Peter Steele
I ended up using

ls /dev/ad*|sort -g -k1.8

Not quite as generic as I wanted but it works...

From: Oliver Mahmoudi [mailto:olivermahmo...@gmail.com]
Sent: Sunday, November 29, 2009 10:36 AM
To: Peter Steele
Cc: freebsd-questions@freebsd.org
Subject: Re: Sorting a device list

you can try to delete the /dev/ad10 entry with sed and then just append it to 
the end manually using the
printf(1) utility like so:

# ls /dev/ad* | sed s/\/dev\/ad10// | grep /dev/ad  printf /dev/ad10\n

Does that help?

Oliver




On Sun, Nov 29, 2009 at 6:56 AM, Peter Steele 
pste...@maxiscale.commailto:pste...@maxiscale.com wrote:
I had tried that. It doesn't work:

# ls -d1 /dev/ad* | sort -n
/dev/ad10
/dev/ad4
/dev/ad6
/dev/ad8
I want the ad10 to appear last...

-Original Message-
From: Giorgos Keramidas 
[mailto:keram...@ceid.upatras.grmailto:keram...@ceid.upatras.gr]
Sent: Saturday, November 28, 2009 4:31 PM
To: Peter Steele
Cc: freebsd-questions@freebsd.orgmailto:freebsd-questions@freebsd.org
Subject: Re: Sorting a device list

On Sat, 28 Nov 2009 11:48:18 -0600, Peter Steele 
pste...@maxiscale.commailto:pste...@maxiscale.com wrote:
 Can anyone recommend a quick and dirty way to sort a device list? For 
 example, if I do this:

 ls /dev/ad* | sort

 I get something like this:

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

Just use `sort -n':

   ls -d1 /dev/ad* | sort -n

It should work fine even when there are non-numeric prefix strings.


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

___
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


Re: Sorting a device list

2009-11-29 Thread perryh
Oliver Mahmoudi olivermahmo...@gmail.com wrote:
 you can try to delete the /dev/ad10 entry with sed and then just
 append it to the end manually using the printf(1) utility like so:

 # ls /dev/ad* | sed s/\/dev\/ad10// | grep /dev/ad  printf
 /dev/ad10\n

Or strip the non-numerics from the beginning of each line, and put
them back after sorting:

# pfx=/dev/ad ; ls -d1 ${pfx}* | sed s;$pfx;; | sort -n | sed s;^;$pfx;
___
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


Sorting a device list

2009-11-28 Thread Peter Steele
Can anyone recommend a quick and dirty way to sort a device list? For example, 
if I do this:

ls /dev/ad* | sort

I get something like this:

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

I can add -g, but it doesn't help:

ls /dev/ad* | sort -g

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

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?

___
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


Re: Sorting a device list

2009-11-28 Thread Giorgos Keramidas
On Sat, 28 Nov 2009 11:48:18 -0600, Peter Steele pste...@maxiscale.com wrote:
 Can anyone recommend a quick and dirty way to sort a device list? For 
 example, if I do this:

 ls /dev/ad* | sort

 I get something like this:

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

Just use `sort -n':

ls -d1 /dev/ad* | sort -n

It should work fine even when there are non-numeric prefix strings.


___
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


RE: Sorting a device list

2009-11-28 Thread Peter Steele
I had tried that. It doesn't work:

# ls -d1 /dev/ad* | sort -n
/dev/ad10
/dev/ad4
/dev/ad6
/dev/ad8

I want the ad10 to appear last...

-Original Message-
From: Giorgos Keramidas [mailto:keram...@ceid.upatras.gr] 
Sent: Saturday, November 28, 2009 4:31 PM
To: Peter Steele
Cc: freebsd-questions@freebsd.org
Subject: Re: Sorting a device list

On Sat, 28 Nov 2009 11:48:18 -0600, Peter Steele pste...@maxiscale.com wrote:
 Can anyone recommend a quick and dirty way to sort a device list? For 
 example, if I do this:

 ls /dev/ad* | sort

 I get something like this:

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

Just use `sort -n':

ls -d1 /dev/ad* | sort -n

It should work fine even when there are non-numeric prefix strings.


___
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