Patrick Reis de Souza
Patrick Reis de Souza

Reputation: 33

SED how to replace Line with Regex

quick question

I have this line:

regexp: \[apm,(.*)\]apm-(.*)\.pivotal

And I want to be like that:

regexp: \[apm,(.*)\]app-metrics(.*)\.pivotal

The sed command that I'm using and it's not working is that one:

sed -i -E 's/regexp: \\[apm,(.\*)\\\]apm-(.\*)\\.pivotal/regexp: \\[apm,(.\*)\\\]app-metrics(.\*)\\.pivotal/g' FILE_THAT_CONTAINS_THE_LINE

Upvotes: 1

Views: 57

Answers (2)

Vorsprung
Vorsprung

Reputation: 34337

sed -i -E 's/regexp: \\\[apm,\(\.\*\)\\\]apm-\(.\*\)\\\.pivotal/regexp: \\[apm,(.*)\\]app-metrics(.*)\\.pivotal/' file.txt

you have some escapes missing

Upvotes: 1

Ivan
Ivan

Reputation: 7277

Try to simplify it

sed '/regexp:.*apm.*apm-.*pivotal/s/apm-/&metrics/' FILE...

Upvotes: 2

Related Questions