[ILUG] sorting filenames ?
Brian Foster
blf at blf.utvinternet.ie
Tue May 1 17:05:18 IST 2007
| Date: Tue, 1 May 2007 15:14:37 +0100
| From: "Declan Grady" <declan.grady at nuvotem.com>
|[ ... ]
| for i in `cat $TEMPFILENAME | awk 'BEGIN {FS="_"}{print $1"_"$2}' | sort -u`
| do
| $ADDTIFFFILES `cat $TEMPFILENAME | grep $i\_` $i.tif
| $CONVERTTOPDF $i.tif >$i.pdf
| # do some other stuff
| done
as an aside, this wins a Useless Use of cat Award™.
awk(1) can read files.
so the `cat ... | awk ... | sort -u` backticked(!)
pipe can also be written as:
$( awk -F_ -- '{ print $1 "_" $2 }' "$TEMPFILENAME" | sort -u )
note I've also used the -F option to set FS (rather
then the BEGIN action, just to make the line a bit
more readable (IMHO)), both the -- end-of-options
maker and a "quoted" filename as safety precautions,
and the much-more-readable $( ... ) notation rather
than the obsolete `back ticks`.
( I've also inserted a few (spurious) spaces for
readability, albeit the original is Ok (IMHO). )
as an exercise to the reader, the grep can also be
improved somewhat. however, since there are some
strong assumptions being made about the contents
of $TEMPFILENAME, it is, to some extent, pointless.
apologies, this question just caught me in a very-
annoyed-at-some-scripts mood ..... ;-\
cheers!
-blf-
--
▶ ▶ I AM CURRENTLY LOOKING FOR A JOB! ◀ ◀ | Brian Foster
Experienced (>25 yrs) software engineer: | Montpellier, FRANCE
• Unix, Linux, embedded, design-for-test; | Stop E$$o (ExxonMobile)!
• Software/hardware co-design, debugging; | http:/www.stopesso.com
• Kernels, drivers, filesystems, &tc; Résumé (CV) & contact details:
• IDL, automated testing, process, &tc. http://www.blf.utvinternet.ie
More information about the ILUG
mailing list