Sed command doesn't work on mac

The following sed command does not work on my mac lion.

find . -type f -exec sed -i 's/user_dashboard/user/g' {} \; 

I get this error

 sed: 1: "./vendor/assets/javascr ...": invalid command code . 
+4
source share
3 answers

The OSX sed version is not the same as most Linux systems.

It extends the -i option to give you the option to save a file with a different extension, but requires input for this extension.

If you just want to overwrite the file in place, you need to use sed -i "" ...sedCmd.... fileName to rename your file in place.

In a comment by @JamesMcMahon, see the full document for OSX / BSD sed here .

Hope this helps.

+19
source

-i probably has a different meaning (not "in place") in your version of sed. Try using gsed if possible, or replace -i with -e and use a temporary file (and mv ) for this.

+6
source

it is possible to replace text inside a text file with sed on mac.

the team is a little different.

with: -i, you specify the extension in which sed will save the source file until the sed operation.

run the command as:

$ sed -i _bakup -E / THESTRING / THEGRANDSTRING '/tmp/jestinkt.txt

+1
source

Source: https://habr.com/ru/post/1401904/


All Articles