sorting pathnames by basename
Erik Price
erikprice at mac.com
Tue Aug 20 00:39:29 EDT 2002
On Monday, August 19, 2002, at 05:32 PM, Kevin D. Clark wrote:
>
> Bill Freeman <f at ke1g.mv.com> writes:
>
>> Use Python
>
> Please show us the code.
#!/usr/bin/python
#
# basenamesort.py
#
# Unix-style filter that sorts a newline-separated
# list of files by the file basename
#
# Example usage: cat files.txt | basenamesort.py
import sys
import os
tempDict = {}
for line in sys.stdin.xreadlines():
tempDict[os.path.basename(line)] = line.rstrip()
sorted = tempDict.keys()
for key in sorted:
print tempDict[key]
# Ugly even for Python, but it does what Michael originally wanted.
--
Erik Price
email: erikprice at mac.com
jabber: erikprice at jabber.org
More information about the gnhlug-discuss
mailing list