Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Lifequest

macrumors regular
Original poster
Feb 9, 2010
109
0
I'm completely new to this and have stitched up some things I've found on forums to try and create a bulk renaming workflow where a folder contains items to be renamed based on a csv list.
Files appear to be renamed properly there is just a "?" in the file extension and I don't know where this could have happened; assistance is greatly appreciated!
I've taken some screenshots as below, I've also included the excel and textedit screenshots of the list.
automater.jpg
output.jpg
csv.jpg
textedit.jpg
 

chown33

Moderator
Staff member
Aug 9, 2009
10,784
8,513
A sea of green
Without having the actual text file in hand, my first guess is that you have an errant character on the end of the shell variable 'line', and this is ending up as the last char of the assignment to NewNewImageName. It then gets used to rename the file, and the Finder shows the errant character as '?' rather than something more informative.

The easiest way to find out what's in the 'line' variable is to echo it. You can put this as the first line between your do/done lines, or replace the entire body of do/done with it.
Code:
echo -n "$line" | hexdump -C


You could also apply the 'hexdump -C' to the CSV text file, and post the output.

An 'ls' command in the dir with the JPG's, piped to 'hexdump -C', might also be informative.


A completely different approach would be to process the CSV file with 'awk', with the -F option set to comma, and have it print a series of 'cp' or 'mv' commands, which are later piped to a shell to be executed.

Awk has a 'system' command that can run shell commands, but I've always had better luck by first seeing the commands, then executing them. That is, the first step is to make the 'awk' program print everything correctly, as manually verified by inspection. Once it's been verified as correct, only then are the commands piped to 'bash' to be executed. This is far safer than executing things blindly.
 
Last edited:

Lifequest

macrumors regular
Original poster
Feb 9, 2010
109
0
Thanks! it was a phantom %0D added to the end which finder displayed as ".jpg?" instead of ".jpg%0D"

For those interested, I found this on the mac discussion forums (by TonyT1- credit given) and it helped:

cd "$1"
while read line
do
OldImageName=${line%,*}
NewImageName=${line#*,}
NewImageName=$( echo "$NewImageName" | tr -d '\r' )
if [ -e "$OldImageName" ] ; then
mv "$OldImageName" "$NewImageName"
else
echo "$OldImageName" >> ~/Desktop/Errors.txt
fi
done <"$2"
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.