I have to rename 100+ files at a time on the server
& was trying to use a script for doing that.
I have used ultra edit to create a file having
current filename & new file name as below
cat file_containing_the_name_pairs | awk -F'|' | while read oldfile newfile
do
# Remove echo when sure that this does what you want
echo mv "${oldfile}" "${newfile}"
done
(Please no stupid comments about "cat", we don't know what O/S or Shell this is?).
cat list|while read a
do
old=`echo "${a}"|cut -f1 -d"|"` ## old file name, first column
new=`echo "${a}"|cut -f2 -d"|"` ## new file name, first column
mv ${old} ${new}
done
---------- Post updated at 06:50 PM ---------- Previous update was at 06:49 PM ----------
1) If necessary I will point you at strong advice about not ever changing "IFS".
2) I continue to stand by the use of "cat" to start pipelines in portable and readable scripts. Reading input from the last line the loop is just about comprehensible in example scripts but incomprehensible on a commercial scale.
@cfajohnson
Agreed. The IFS construct works in many modern shells. Never in dispute - just difficult to follow.
I can write to any local standard, but long experience has shown which constructs are difficult to follow by colleagues and passing contractors.
I too can write obfuscated code which works efficiently but is unmaintainable in a commercial environment.
Sometimes when the data volumes are large and the processing is complex (and I don't have time to write a program) I will use every trick to get a shell script to process the data in the least possible time. The script may be unreadable but it will work.
So vote for the "Clear Code Party" in the next General Election.
(Dismounts high horse and prepares to count both of the votes).
We are in different time zones, and I am getting tired, and with apologies to the O/P for hijacking the post:
I fully agree that the Bourne shell is a sound base for writing portable shell scripts. I do not agree that interfering with IFS is sensible in all common shells.
I must argue this point. It is obfuscated and it is not standard practice. I have scanned thousands of manufacture standard issue scripts and not found one case.
I choose the language to match the specification. There are occasions when awk will do the job, there are occasions when it is just too slow or awkward. I treat awk as a programming language rather than a shell command.