hardeep
hardeep

Reputation: 195

sed with -r and \1 substitution does not work together

$ echo "    <mta abc='1' def='2'>" | sed -r 's/.*\(mta\).*/\1def/g'
sed: -e expression #1, char 21: invalid reference \1 on `s' command's RHS

$ echo "    <mta abc='1' def='2'>" | sed 's/.*\(mta\).*/\1def/g'
mtadef

## Is there a way to make \1 and -r option work together in sed

Upvotes: 1

Views: 739

Answers (1)

Jotne
Jotne

Reputation: 41446

With ERE (Extended Regular Expressions) you do not escape the parentheses, so this works:

echo "    <mta abc='1' def='2'>" | sed -r 's/.*(mta).*/\1def/g'
mtadef

Upvotes: 2

Related Questions