If I have something that looks like this:

hello {sdsdsdsds} pattern {askjdasjkdjasd} hello {siadsd} pattern {iuewer} 

So if pattern if matched before {*}, I need to add a ;. Output:

hello {sdsdsdsds} pattern {askjdasjkdjasd}; hello {siadsd} pattern {iuewer};

And this is just one lines, yes.

Now, I though of something like this:


But I can't quite figure out how to make sed remember the contents of .*.

Then theres this,

'/pattern\ {.*}/ s/$/;/'

But this won't work since it is only one line.


If I correctly understood your question you are looking for

sed 's/\(pattern {[^}]*}\)/\1;/g'

where \1 replaces everything what matched inside \(...\).

The output:

hello {sdsdsdsds} pattern {askjdasjkdjasd}; hello {siadsd} pattern {iuewer};
  • To be more short strip { : sed 's/pattern[^}]*}/&;/g' – Costas Nov 28 '14 at 22:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.