Random shell scripting things I may use in the future
Mass move:
for f in wlog/*; do
for ff in $f/*; do
cp "$ff" $(basename $f)-$(basename $ff | sed 's/^00-//g' | sed 's/ /-/g');
done;
done
Mass Find and replace:
for f in *todo*; do
cat $f | sed -e 's/## '$(basename $f | sed 's/-stand-up-notes.md//')$'/---\\\ndate: "2019-03-01T16:20:01"
title: '$(basename $f | sed 's/-stand-up-notes.md//')$' stand up notes\\\n---'/ | tee $f ;
done
Mass adjust markdown headers:
find . -name '*.md' | while read f; do cat $f | egrep '^##\s' > /dev/null && echo $f; done | while read fn; do cat $fn | sed 's/^##/###/g' | sed 's/^#\s/## /g' | tee $fn; done
Create temp directory:
tmpDir="$(mktemp -d -t tmpdirname.XXXXXXXXXX || oops "Can't create temporary directory")"
cleanup() {
rm -rf "$tmpDir"
}
trap cleanup EXIT INT QUIT TERM