Computing.Net > Forums > Unix > Shell script to read a file and pro

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Shell script to read a file and pro

Reply to Message Icon

Name: kishan24
Date: December 4, 2002 at 11:20:55 Pacific
OS: Windows 2000
CPU/Ram: 128MB
Comment:

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.




Sponsored Link
Ads by Google

Response Number 1
Name: James Boothe
Date: December 10, 2002 at 08:52:26 Pacific
Reply:

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


0
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Shell script to read a file and pro

Unix shell script for opening a file and www.computing.net/answers/unix/unix-shell-script-for-opening-a-file-and/3452.html

shell script that reads a file www.computing.net/answers/unix/shell-script-that-reads-a-file/4967.html

shell script to send a file thru FT www.computing.net/answers/unix/shell-script-to-send-a-file-thru-ft/6428.html