sorting pathnames by basename

Kevin D. Clark kclark at CetaceanNetworks.com
Wed Aug 21 08:52:14 EDT 2002


Bob Bell <bobbell at zk3.dec.com> writes:

> '/' is an illegal character in a filename, right?
> 
> sed -e 's;\(\(.*\)/\)*\(.*\);\3/\1\3;' | sort -fdt/k1 | sed -e 's;[^/]*/\(.*\);\1;'

This doesn't work for me for a number of reasons:

1:  sed is known to contain a number of bugs, and you're hitting one
    of them on my SVR4-derived Solaris box.  That first call to sed
    doesn't yield any changes.

2:  Those options to sort don't work on my Linux box.


Still, I see where you're going here.  How about this?

  sed -e 's;\(.*\)/\([^/]*\)$;\2/\1/\2;' | sort -t / +0 | sed 's;[^/]*/;;'

This works on the various Unix boxen that I have at my disposal.

Regards,

--kevin
-- 
Kevin D. Clark / Cetacean Networks / Portsmouth, N.H. (USA)
cetaceannetworks.com!kclark (GnuPG ID: B280F24E)
alumni.unh.edu!kdc




More information about the gnhlug-discuss mailing list