sorting pathnames by basename
Bob Bell
bobbell at zk3.dec.com
Wed Aug 21 09:30:10 EDT 2002
On Wed, Aug 21, 2002 at 08:52:14AM -0400, Kevin D. Clark <kclark at CetaceanNetworks.com> wrote:
> Bob Bell <bobbell at zk3.dec.com> writes:
> > 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.
Well, I can't be responsible for broken Unixen, now, can I? Fix
your box :-)
> 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).
> 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;[^/]*/;;'
If '-f' and '-d' are problems, you could just drop them. I used them
because they were in the original suggestion, so I figure MOD wanted to
use them in the comparison.
--
Bob Bell <bobbell at zk3.dec.com>
-------------------------------------------------------------------------
"Beware of the above code; I have only proved it correct, not tried it."
-- Donald Knuth, famous computer scientist
More information about the gnhlug-discuss
mailing list