On Mon, Aug 19, 2002 at 03:46:40PM -0400, Michael O'Donnell <[EMAIL PROTECTED]> wrote:
> 
> Given a list of pathnames, I'd like to be able to
> sort that list by the basename of each file in the
> list, ie.  the pathname
> 
>    q/r/s/t/u/v/aaa
> 
> ...would sort ahead of
> 
>    aaaa/aaaa/bbb
> 
> ...because the basename 'aaa' sorts lexicographically
> ahead of 'bbb'.
> 
> My current approach is a bit clunky but works as long as
> the pathnames in question contain no spaces, thus:
> 
>    sed -e 's;/\([^/]*\)$; \1;' | sort -bfd +1 | sed -e 's; ;/;'
> 
> ...which replaces the last slash in each pathname with
> a space, sorts that list of dual-field space-delimited
> records keyed on the second field, and then replaces
> the slashes.  Suggestions for improvement welcome.

'/' is an illegal character in a filename, right?

sed -e 's;\(\(.*\)/\)*\(.*\);\3/\1\3;' | sort -fdt/k1 | sed -e 's;[^/]*/\(.*\);\1;'

-- 
Bob Bell <[EMAIL PROTECTED]>
-------------------------------------------------------------------------
 "Digital files cannot be made uncopyable, any more than water can
  be made not wet."
   -- Bruce Schneier, CRYPTO-GRAM, May 15, 2001
_______________________________________________
gnhlug-discuss mailing list
[EMAIL PROTECTED]
http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss

Reply via email to