Skip to content

Instantly share code, notes, and snippets.

@schlueter
Last active December 10, 2017 17:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schlueter/ae4c9f5510110c5358db074779df3b3c to your computer and use it in GitHub Desktop.
Save schlueter/ae4c9f5510110c5358db074779df3b3c to your computer and use it in GitHub Desktop.
Time use of xargs and awk to rename a set of directories
#!/usr/bin/env bash
set -e
((DEBUG)) && set -x
TIMES=100
WORDS=100
rm -rf $(<head-words)
rm -rf $(<tail-words)
uniq -i /usr/share/dict/words > uniq-words
tail -$WORDS uniq-words > tail-words
head -$WORDS uniq-words > head-words
paste -d' ' head-words tail-words > paired-words
for c in 'cat paired-words | xargs -n2 mv' \
'< paired-words xargs -n2 mv' \
"awk '{system(\"mv \" \$1 \" \" \$2)}' paired-words"
do
echo "Executing $TIMES trials of \`$c\`"
time for n in $(seq 1 $TIMES)
do
mkdir $(<head-words)
sh -c "$c"
rmdir $(<tail-words)
done
echo
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment