Help with sed search&replace between two strings

Hi, i read couple of threads here on forum, and googled about what bugs me, yet i still can't find solution.
Problem is below.
I need to change this string (with sed if it is possible):

[rquote=12345&tid=123456&author=nickname]This is message text that is being quoted[/rquote]

to look like this:

[bquote=nickname]This is message text that is being quoted[/bquote]

I managed to do this by using:

sed 's/\[rquote=.*author=/[bquote=/g'

Ok, it doesen't replace closing tag [/rquote] to [/bquote], but i can run sed again just to replace that.

That works, until it come do double quote, like this:

[rquote=12345&tid=123456&author=nickname][rquote=123456&tid=1234567&author=othernick] This is message text that is being quoted [/rquote]

How can i get above example (with double quote) to be replaced with this:

[bquote=nickname][bquote=othernickname]  This is message text that is being quoted [/bquote]

Some help?

P.S. It is not so impotrant to change those closing tags [/rquote] to [/bquote] in the same sed expression.

Hi,

if your string

[rquote=12345&tid=123456&author=nickname][rquote=123456&tid=1234567&author=othernick] This is message text that is being quoted [/rquote]

is saved in a file called "file". This:

sed 's/rquote[^]]*author/bquote/g;s/rquote/bquote/' file

gives me:

[bquote=nickname][bquote=othernick] This is message text that is being quoted [/bquote]

If you echo your string on the command line, you will have to escape the "&" sings.

HTH Chris

1 Like

It helps just perfectly! :wink: Tried it on one big post with lots of quotes and it works exelent. Later i will run it over whole db dump and report results.
Big thx Cris!