Reputation: 195
$ 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
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