Reputation: 3085
I am trying to run a script which corrects line breaks in all PHP files. This is how it looks like:
find . -type f -name \*.php -print -exec sed -i '' 's/\r//' {} \;
The errors I get for all files is:
./downloader/lib/Mage/Backup/Exception/SomeFile.php sed: can't read
s/\r//: No such file or directory
Whats the error in the script?
Thanks
Upvotes: 1
Views: 3478
Reputation: 72425
The problem is on -i
, it depends on the OS you use.
sed -i '' 's/\r//' {}
On macOS, sed
expects the file extension to use for the backup file as a separate argument, following -i
. An empty string, as you use, tells it to not create a backup file.
On Linux, sed
expects the file extension to be joined together with -i
in a single argument. For example, -i.bak
to append .bak
to the file name to generate the name of the backup file or -i
to not create a backup file.
Since you get an error that says that the file 's/\r//'
does not exist it means that you are using Linux and ''
is interpreted as the sed
program.
Remove ''
and it should work:
sed -i 's/\r//' {}
Upvotes: 3
Reputation: 419
You can do the following:
find . -type f -name \*.php -print -exec sed -i 's/\r//' {} \;
The issue is sed is expecting sed -i <substitution_pattern> <file>
. In your incantation, the ''
is interpreted as the substitution pattern, then the 's/\r//'
is being interpreted as the file
Upvotes: 1