-
All replies
-
Helpful answers
-
Mar 26, 2014 1:24 PM in response to bj49wdby Tony T1,That is strange.
What happens if you:
while read line
do
OldImageName=${line%,*}
NewImageName=${line#*,}
cp "$OldImageName" "$NewImageName"
rm $OldImageName"
done <"$2"
or:
while read line
do
OldImageName=${line%,*}
NewImageName=${line#*,}
ditto "$OldImageName" "$NewImageName"
rm $OldImageName"
done <"$2"
ditto might work as it preserves extended attributes (but mv should have also)
-
Mar 26, 2014 1:35 PM in response to Tony T1by bj49wd,neither of those worked.
Not sure if this is relevant, but the line: rm $OldImageName" didn't have a preceeding " so I added one. (The script as written was throwing an error.)
So, rm "$OldImageName" allowed it to run correctly. However... the files produced are still "documents" and not .wav files.
-
Mar 26, 2014 1:38 PM in response to bj49wdby Tony T1,Last try with rsync:
while read line
do
OldImageName=${line%,*}
NewImageName=${line#*,}
rsync -a "$OldImageName" "$NewImageName"
rm "$OldImageName"
done <"$2"
-
Mar 26, 2014 2:03 PM in response to Tony T1by bj49wd,Bah! Same result.
I'm wondering about the shell script, and possible typos... should
NewImageName=
${line#,*}
and not
${line#*,}
UPDATED:
Clearly not. Making this change just adds the two names together.
I'm super novice script man.
Message was edited by: bj49wd
-
Mar 27, 2014 1:34 PM in response to Tony T1by bj49wd,Hey Tony,
I really appreciate your help on this. I don't want to beat a dead horse, nor do I want anyone else to on my behalf. I thought I'd just add one last update to this thread:
When I rename the file... I notice that there is a carriage return AFTER the extension! This line break isn't apparent in my CSV file, and I'm not sure where it's coming from.
Trying to rename the file reveals that there is a space beneath the file name. After I delete it—just the space—I get an alert about changing the extension. The option to keep the current extension ALSO has the line break.
Food for thought.
-
Mar 27, 2014 3:33 PM in response to bj49wdby Tony T1,Ah! Good catch
Adding this line should get rid of the carriage return (if it's a UNIX \n return)
NewImageName=${NewImageName//\\n}
So try:
while read line
do
OldImageName=${line%,*}
NewImageName=${line#*,}
NewImageName=${NewImageName//\\n}
mv "$OldImageName" "$NewImageName"
done <"$2"
-
Mar 27, 2014 3:48 PM in response to Tony T1by bj49wd,Tried it. The return is still present in the resulting filename.
-
Mar 27, 2014 3:56 PM in response to bj49wdby Tony T1,In the script, add:
echo "$NewImageName" > ~/Desktop/text.txt
cat -e ~/Desktop/text.txt
And Run the script in Terminal (not Automator)
This will show if it's \n or \r\n
-
-
Mar 27, 2014 4:13 PM in response to bj49wdby Tony T1,^M is \r, so try
NewImageName=${NewImageName//\\r}
or
NewImageName=${NewImageName//\\r\\n}
-
Mar 27, 2014 4:18 PM in response to Tony T1by bj49wd,Hmm, no deal for either solution. Somehow, a return is still getting added to the end of the file extension.
I wonder if adjusting the CSV to hold the file name only, and then add the extension via the workflow... might that be a workaround? (clueless)
I appreciate your help here, if you have better things to do than to mess with this, I totally understand!
-
Mar 27, 2014 4:58 PM in response to bj49wdby Tony T1,Got it. Need $'\r'
Words of the form $'string' are treated specially. The word expands to string, with backslash-escaped characters replaced as specified by the ANSI C standard
This should do it
NewImageName=${NewImageName//$'\r'}
so:
while read line
do
OldImageName=${line%,*}
NewImageName=${line#*,}
NewImageName=${NewImageName//$'\r'}
mv "$OldImageName" "$NewImageName"
done <"$2"
-
Mar 27, 2014 4:51 PM in response to bj49wdby Hiroto,Hello
In oder to remove trailing CR from the variable, you may use:
NewImageName=${NewImageName%$'\r'}Regards,
H
-
Apr 1, 2014 3:39 PM in response to Tony T1by bj49wd,Tony For The Win!!
$'\r' was the ticket. That worked. I have no idea how that return got IN to the filename, but you got it OUT. Thank you so much!
Thanks for sticking this one out.
-
Apr 1, 2014 4:04 PM in response to bj49wdby Tony T1,Usually (but not always) the \r comes from Windows files.


