Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mass file rename from data in a CSV

Status
Not open for further replies.

Zugdud

IS-IT--Management
Feb 26, 2003
158
US
Greetings all, I was wondering if it would be possible to rename a bunch of files based on information from a CSV? For example, here is some data from the CSV:

Oldname Newname
file1 file1_a
file2 file2_b
file3 file3_c
file4 file4_c

Is it possible to rename a directory of files from the old name to the newname in the CSV? Any ideas on what direction I should take or if its possible without major programming?

Thankyou for any insite
 
Sorry, the actual CSV looks like this , not tabulated columns:

file1,file1_a;
file2,file2_b;
file3,file3_c;
file4,file4_c;
 
[tt]
awk '
BEGIN { FS = ",|;" }
3==NF {
cmd = "mv " $1 " " $2
system( cmd )
}' /path/to/input
[/tt]
 
Hi:

Assuming:

file1,file1_a;
file2,file2_b;
file3,file3_c;
file4,file4_c;

is in mydata.file:

#!/bin/ksh

# no error checking
while IFS=",;" read col1 col2
do
mv $col1 $col2
done < mydata.file

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top