Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi,
I am trying to read a file which has two fields i.e tab seperated.
Each line has an OldImage Name and a NewImage Name.
Can anyone help me to write a shell script which reads the file and changes the image name to the newer one.No Need to check if image exists or not and the permissions of the file.
Thanks in advance.

So this file contains file names, and you want each old filename renamed to each new filename? If so, the following script will do that.
Note that TAB needs to be an actual tab character, and not the word TAB.
No checks are done to see if the move will be or was successful. If you do not want to see error messages, you can redirect the mv stderr to /dev/null. If new name already exists, the mv command will blow that file away, assuming permissions allow. Delete the print command if you do not want those message lines.
#!/bin/sh
cat myfile |
while IFS="TAB" read word1 word2 other
do
print "Renaming $word1 to $word2 ..."
mv $word1 $word2
done
exit 0

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |