I need to use sed to:Replace Strings Such as:tr(Text);TO text;tr(Textfsafasfsfassafasdfsafas);TOTextfsafasfsfassafasdfsafas; foo(tr(text)); TOfoo(text);Do Not Replace these Strings:tr(text).arg(text);tr(I am some text).arg(i do stuff);tr(I am some text).arg(i do stuff).arg(I also do stuff); where it needs to be handled from 1 up to n lines of this.My current code does not cover the multi-line .arg edge case. Any bright ideas?Current sed code:sed -i  '/\btr(/{ :a; s/\btr(\([^)]*\))\([^.]\)/\1\2/I; t; N; ba}' $file_tEdit:errors << tr(Error: Encountered an invalid token at line: %1, column: %2.)                        .arg(m_reader.lineNumber())                        .arg(m_reader.columnNumber());is an edge-case that is still an issue at this time.
Sed - Multi-Line Pattern matching after finding first part of a pattern
sed;regular expression
$ cat ip.txt tr(Text);tr(Textfsafasfsfassafasdfsafas);foo(tr(text));tr(text).arg(text);tr(I am some text).arg(i do stuff);tr(I am some text).arg(i do stuff).arg(I also do stuff);tr(I am some text)    .arg(i do stuff);If file is small enough to hold in memory after slurping all lines as single string,$ perl -0777 -pe 's/\btr\(([^)]+)\)(?!\s*.arg)/$1/g' ip.txt Text;Textfsafasfsfassafasdfsafas;foo(text);tr(text).arg(text);tr(I am some text).arg(i do stuff);tr(I am some text).arg(i do stuff).arg(I also do stuff);tr(I am some text)    .arg(i do stuff);If the output is okay, add the -i or -i.bak option for inplace editingEdit:Thanks @Costas for pointing out that \n?\s* can be reduced to \s*