Find all files with text "example.html" and replace with "example.php" works only if no spaces are in file name

Viewed 228

I have used the following to do a recursive find and replace within files, to update hrefs to point to a new page correctly:

#!/bin/bash
oldstring='features.html'
newstring='features.php'
grep -rl $oldstring public_html/ | xargs sed -i s@"$oldstring"@"$newstring"@g

It worked, except for a few files that had spaces in the name.

This isn't an issue, as the files with spaces in their names are backups/duplicates I created while testing new things. But I'd like to understand how I could properly pass paths with spaces to the sed command, in this query. Would anybody know how this could be corrected in this "one liner"?

2 Answers
Related