replace string across multiple files with sed

Here’s a useful mac osx / linux trick that helps with replacing a string across multiple files using sed.

I am trying to replace

setApply(“s1”, “parallel”) 

with

     configApplyParallelization(“s1”, “dynamic-vertex-parallel”)

The command is

sed -i ” ‘s/setApply(\”s1\”, \”parallel\”)/configApplyParallelization(\”s1\”,\”dynamic-vertex-parallel\”)/g’ *.gt

The trick for mac osx is that you need an empty string after the -i, otherwise you get an error message

     extra characters at the end of p command

Only figured this out thanks to this post

https://myshittycode.com/2014/07/24/os-x-sed-extra-characters-at-the-end-of-l-command-error/

I believe you don’t need this on linux, the original post here

https://stackoverflow.com/questions/11392478/how-to-replace-a-string-in-multiple-files-in-linux-command-line

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s