filenames with spaces

I downloaded Unity last week. My first bit of installation geekery was to push the documentation to marmaduke, my CentOS server. I drop the documentation directory into a virtual host and let apache serve the index (since I solved my Apache Directory Indexing problem a bit back.)

However, I found that the pages had missing images. Looking at the HTML source, I found that some of the image URLs used ‘images’ (lower case i) while others used ‘Images’ (upper case I). To make matters worse, CSS and javascript files were also stored in the images directory.

I wanted to simply change all occurances of Images to images. The Unity docs have a lot of files. How many? Just under four thousands.

$ find -name '*html' | wc --lines

Shouldn’t be too hard of a script. However, piping the output of find didn’t work since many filenames contained spaces. Spaces in filenames cause problems.

The bash for loop treated the spaces as token markers. To solve this, I simply dumped the filenames to a tempfile and read them back in. I’m sure there’s a one liner somewhere but this solved my problem.

Solution: bash, find and perl search and replace over multiple files and the filenames contain spaces.


find -name '*html' > filenames

while read line; do
  perl -pi -e 's/Images/images/g' "${line}"
done < filenames

rm filenames

Your email will never published nor shared. Required fields are marked *...



Type your comment out: