I have a folder that contains files like this :
s-10.tgz s-11.tgz s-12.tgz
and a text file as follows :
s-10 Tom
s-11 Harry
s-12 Peter
How to rename the files to
Tom.tgz Harry.tgz Peter.tgz
based on the text file.
CodePudding user response:
One way is to read
the file and then do a substring expansion. Only works if there are no spaces in the filenames though.
while read line;do echo "${line% *}.tgz" "${line##* }.tgz" ;done < file
s-10.tgz Tom.tgz
s-11.tgz Harry.tgz
s-12.tgz Peter.tgz
Replace echo
with mv
if everything looks ok.