recently just tried to write a script so I could rename multiple files from two txt files in correct order, it kinda works but not getting the results I’m looking for.
If anyone can see what’s wrong with this please let me know!
IFS=$'n' for i in $(cat ../temp/files.txt); for j in $(cat ../temp/filenames.txt); do mv $i $j; done
Advertisement
Answer
Assuming that both files have exactly the same number of lines (each line representing a filename), and filenames don’t contain a new-line nor a tab character, a quick-and-dirty bash solution (using the paste
utility) could be:
while IFS=$'t' read -r from to; do echo mv "$from" "$to" done < <(paste from.txt to.txt)
Remove the echo
after testing and making sure it will work as intended.