Skip to content

Instantly share code, notes, and snippets.

@espinz
Created September 17, 2019 22:13
Show Gist options
  • Save espinz/ca565801aa40b673db400343449927f3 to your computer and use it in GitHub Desktop.
Save espinz/ca565801aa40b673db400343449927f3 to your computer and use it in GitHub Desktop.
renaming directories
COUNT=$(ls | grep -E "Chapter\ [0-9]" | cut -d ' ' -f 3-10 | wc -l)
for x in `seq 0 $COUNT`; do
if [ "$x" -eq "0" ]; then
newDIRS=$(ls | grep -E "Chapter\ [0-9]" | cut -d ' ' -f 3-10 | head -n 1)
mkdir "$x. ${newDIRS}"
else
DIRS=$(ls | grep -E "Chapter\ [0-9]*" | sort -k2 -n | cut -d ' ' -f 3-10 | tail -n 15 | sed -n ${x}p)
newDIRS=$(ls | grep -E "Chapter\ [0-9]" | cut -d ' ' -f 3-10 | sed -n ${x}p)
mkdir "$x. ${DIRS}"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment