<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 17 August 2014 13:53, William Muriithi <span dir="ltr"><<a href="mailto:william.muriithi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" target="_blank">william.muriithi-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I have a list of files that have horrible names and it is forcing me<br>
to improve the intelligence of a script I have been using to clean up<br>
the system after the images have been processed. Sample names are as<br>
below<br>
<br>
'004378858 (152).jpg'<br>
'004384040.jpg'<br>
'004382728.jpg'<br>
'004383192.jpg'<br>
'004375871.jpg'<br>
'004378858 (179).jpg'<br>
'004378858 (155).jpg'<br>
'004378858 (187).jpg'<br>
<br>
<br>
If i run either of the below commands on the console, it list them<br>
properly as above.<br>
<br>
#LIST=`find /home/wmuriithi/images/   -type f | cut -d"/" -f4| sed 's@<br>
@\\ @g' | sed 's@[(]@\\(@' | sed 's@[)]@\\)@'`<br>
#LIST=`find /home/wmuriithi/images/   -type f | cut -d"/" -f4|sed -e<br>
"s/.*/'&'/"`<br>
<br>
If I run it on a loop, it breaks the file name into two if the name has a space<br>
<br>
for f in $LIST;<br>
  do<br>
<br>
     mv /home/wmuriithi/images/"$f" /home/wmuriithi/archive/images/"$DATE"/<br>
#    echo "rm $f" >> processed.list<br>
     echo "rm $f" >> processed.list2<br>
<br>
  done<br>
<br>
I get this error:<br>
<br>
mv: cannot stat `/home/wmuriithi/images/\'004378858': No such file or directory<br>
mv: cannot stat `/home/wmuriithi/images/(38).jpg\'': No such file or directory<br>
mv: cannot stat `/home/wmuriithi/images/\'004378858': No such file or directory<br>
mv: cannot stat `/home/wmuriithi/images/(53).jpg\'': No such file or directory<br>
<br>
Now, I am curious, why do I get different behaviours above?  What's a<br>
better way of handling such a file name?<br>
<br>
Thanks in advance<br>
<br>
William<br></blockquote></div><br></div><div class="gmail_extra">Others have made some cogent points about the use of parentheses and spaces in file names that I won't repeat, except to say I agree.  Another thing I'd strongly suggest is using the "basename" command instead of "cut": your use of cut relies on knowing how deep in the directory structure you are, and that makes the script very fragile.  basename just grabs the terminal filename and discards all the directories regardless of how deep you are in the directory tree.<br>
</div><div class="gmail_extra"><br>-- <br>Giles<br><a href="http://www.gilesorr.com/">http://www.gilesorr.com/</a><br><a href="mailto:gilesorr@gmail.com">gilesorr-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org</a>
</div></div>