I have a number of files in various directories e.g
\images\00101191
\images\Books
etc.
I would like to rename these. I have exported their paths to a CSV file, which contains information in the format 'old path and name', 'new path and new name' e.g.
\00101191\XYZ123.jpg,\Homeware\TravelMugXYZ123.jpg
I have tried the command
sed 's/"//g' files.csv | while IFS=, read orig new; do mv "$orig" "$new"; done
as per this thread but it removes the slashes, so I just get errors of the form
mv: cannot stat '00101191XYZ123.jpg': No such file or directory
I expect the solution is simple, but I cannot get the syntax to work for me. Any help would be much appreciated. Thanks.
EDIT - actual lines from csv:
/00101234/1101.jpg,/Jewellery/ALittleThankYouTeacher1101.jpg
/00101234/1102.jpg,/Jewellery/ALittleThinkingOfYou1102.jpg
/00101234/1155.jpg,/Jewellery/ALittleDreamcatcher1155.jpg
/00101234/1203.jpg,/Jewellery/ALittleLuckyElephant1203.jpg
EDIT 2
ls -ld /00101234 /Jewellery
ls: cannot access '/00101234': No such file or directory
ls: cannot access '/Jewellery': No such file or directory
EDIT 3
Today I learned how little I know. Thanks for your ongoing help - I have the following output which hopefully may help?
user@Laptop:~/Desktop/images$ ls -ld /00101234 /Jewellery
ls: cannot access '/00101234': No such file or directory
ls: cannot access '/Jewellery': No such file or directory
user@Laptop:~/Desktop/images$ cd 00101234
user@Laptop:~/Desktop/images/00101234$ cd ..
user@Laptop:~/Desktop/images$ cd Jewellery
user@Laptop:~/Desktop/images/Jewellery$ cd ..
user@Laptop:~/Desktop/images$ ls -ld \00101234 \Jewellery
drwxrwxr-x 2 user user 32768 Jan 8 16:56 00101234
drwxrwxr-x 3 user user 20480 Jan 8 16:25 Jewellery
EDIT 4
I feel like I must be missing something - but using the information from @wjandrea / @dessert and @terdon I think I've got somewhere.
The command I'm using is
while IFS=, read -r orig new; do "/home/me/Images$orig" "/home/me/Images/NEW$new"; done < files.csv
I should add that I've copied the folder of files to be renamed to /home/me/Images and put the csv file there too. I added /NEW so I can easily find the renamed files, as it occurred to me that some of the folders specified in the CSV already exist and have files in.
The issue I now have is that I get the error Permission Denied, e.g.
bash: /home/me/Images/Xmas/XmasCushion.jpg: Permission denied
but I do have permission as far as my (very limited) knowledge takes me
me@laptop:~$ ls -l /home/me/Images/Xmas/
total 176
-rw-rw-rw- 1 me me 94208 Mar 5 2018 Thumbs.db
-rw-rw-rw- 1 me me 48274 Sep 13 14:34 XmasCushion.jpg
-rw-rw-rw- 1 me me 31553 Sep 13 14:34 XmasBunting.jpg
About the only thing I know to do if there is a permission issue is to sudo it, but then I get the error
bash: syntax error near unexpected token `do'
I've learned some stuff through your help -thanks all. Apologies for still not getting it to work.
;s/\\/\//g
to yoursed
command should do it. ==>sed 's/"//g;s/\\/\//g' files.csv | ...
/
, or are they relative to your current directory?/00101234/
? And one called/jewlery
? What is the output ofls -ld /00101234 /jewlery
?/foo
is the equivalent ofC:\foo
and I think you want paths relative to your home directory. So, please edit your question and show usls -ld /00101234 /Jewlery
which will tell us if those directories exist.orig.jpg new.jpg
and not move it. You need themv
command to move it:mv orig.jpg new.jpg
. Read my answer again and copy the command correctly:while IFS=, read -r orig new; do mv "/home/me/Images$orig" "/home/me/Images/NEW$new"; done < files.csv