sorting pathnames by basename
Kevin D. Clark
kclark at CetaceanNetworks.com
Wed Aug 21 11:03:56 EDT 2002
Bob Bell <bobbell at zk3.dec.com> writes:
> Fix your box :-)
Point taken, although I try to write portable code, and as such, I
will always be a little bit conservative when I am using sed.
> > 2: Those options to sort don't work on my Linux box.
>
> Really? They work on mine. What `sort` do you have? Mine's from
> a textutils-2.0e-8 RPM. All options I used are part of UNIX 98
> (http://www.opengroup.org/onlinepubs/007908799/xcu/sort.html).
$ rpm -q -f /bin/sort
textutils-2.0.21-1
> > 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.
>
> Nope, you've just forced the pathname to contain a '/'. But here's
> a simplified version that I think will work around your issues for
> non-UNIX 98 compliant machines:
>
> sed -e 's;\(.*/\)*\(.*\);\2/\1\2;' | sort -f -d -t / +0 | sed -e 's;[^/]*/;;'
My example, derived from yours, seems to work, as well as your new
solution.
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