Multi line replacement with Sed -


i have file this:

function a() {   dosomething();   dosomethingelse(); } 

now need replace text between function a() { , } other text

i tried several ways found here, failed. hope explanation along answer.

p.s. trick need compatible both os x , gnu sed.

you can standard substitution :

sed -i 's/\(\<\)dosomething()/\1somethingelse()/' your_file 

we use word boundary delimit string :

\(\<\)dosomething() 

and replace string new string (including captured word boundary) :

\1somethingelse() 

the -i flag stands : inline replacement


i used sample file :

function a() {   dosomething(); dosomething();   foo();dosomething(); } 

output :

function a() {   somethingelse(); somethingelse();   foo();somethingelse(); } 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -