1

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

2 Answers 2

3

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//' {}
Sign up to request clarification or add additional context in comments.

Comments

1

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

3 Comments

And it does exactly the same?
It does what I believe you intended to do. If I run the exact incantation in my answer, I get: $ find . -type f -name \*.php -print -exec sed -i 's/\r//' {} \; ./something.php
If I run the incantation in your post, I get: $ find . -type f -name \*.php -print -exec sed -i '' 's/\r//' {} \; ./something.php sed: can't read s/\r//: No such file or directory

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.