Skip to content

Instantly share code, notes, and snippets.

@zawyelwin
Last active December 15, 2020 20:20
Show Gist options
  • Save zawyelwin/17deb36138853a1fe4e5e76835e64815 to your computer and use it in GitHub Desktop.
Save zawyelwin/17deb36138853a1fe4e5e76835e64815 to your computer and use it in GitHub Desktop.
Rename all files in a directory based on the line number from a txt file.

Original File name

1.mp4 2.mp4 3.mp4 4.mp4

title.txt

1-abc
2-def
3-ghi
4-jkl

After Running Script

1-abc.mp4 2-def.mp4 3-ghi.mp4 4-jkl.mp4
#!/bin/bash
for i in *.mp4
do line=$(awk "NR==${i}" title.txt)
mv -- "$i" "${line}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment