10 Aug'13

Rename all *.rst files in a directory according to their date

TODO:

  • add verbose mode
  • move awk output into variable and test if file already begins with a date
#!/bin/sh
for f in $(find ./content/ -name '*.rst'); do
    name=$(basename "$f")
    dd=$(dirname "$f")
    d="$dd/$(cat "$f" | grep ':date:' | awk '{print $2}')-$name"
    if [ ! -f "$d" ]; then
        mv "$f" "$d"
    else
        echo "File '$d' already exists! Skiped '$f'"
    fi
done

Comments