Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Need help with simple script (Renaming files with csv)

I have a folder of jpgs I need to rename and a .csv that has the old and new names listed in it. I'm trying to use this script:


while IFS=';' read -r old_name new_name _; do
printf 'Renaming "%s" to "%s"\n' "$old_name" "$new_name"
mv "$old_name" "$new_name"
done < list.csv


But I haven't been able to get it to work... All that happens is this:


UFO:pics john$ while IFS=';' read -r old_name new_name _; do


set -x


printf 'Renaming "%s" to "%s"\n' "$old_name" "$new_name"


mv "$old_name" "$new_name"


done < list.csv


IFS=';'


read -r old_name new_name _


++ update_terminal_cwd


++ local 'SEARCH= '


++ local REPLACE=%20


++ local PWD_URL=file://UFO.local/Users/john/desktop/pics


++ printf '\e]7;%s\a' file://UFO.local/Users/john/desktop/pics


UFO:pics john$


Any help greatly appreciated!!!

Posted on Oct 8, 2015 8:30 AM

Reply
5 replies

Oct 8, 2015 11:29 PM in response to disguise

Thanks so much for your help! I tried that script but still no luck, nothing happened in the end, not sure what the problem is. Here is what I used (After I cd to the folder with the files & list of course) Also I changed the delimiter to ";" because thats how my list is set up


#!/bin/bash

set IFS=";"


while read old_name new_name

do

echo "old_name = $old_name"

echo "new_name = $new_name"

mv $old_name $new_name

done < list.csv


If I just copy and paste this line for line into terminal it should work right? Also does the extra space between the IFS line and while mean anything, or the way the echo lines are indented? Sorry, I am a beginner at bash so I am probably making some dumb mistake. Have you tried the script? Do you have any ideas what I could be doing wrong? thanks a lot!!!

Need help with simple script (Renaming files with csv)

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.