Translating Filenames — Bash Voodoo Style #linux

This is an example of using Bash to convert a crazy apache log and translating the filename into an IIS log pattern:

d=`date +%Y%m%d`
find k -type f \
| while read filename
do
  nextfile="${filename/k\/done?0.www\./k2/www-Server_T${d}_}.log"
  echo "$nextfile"
  cat $filename | $translate > "$nextfile"
done

I love how I can refer to a shell variable ($d) inside a string translation (${d}).

Advertisements