Ivan Martinez
Ivan Martinez

Reputation: 39

Need help to replace complex string with sed

The file index.jsp contains this string:

'+sessionServerId + '' + countryAssetsInternationalization;

I need to replace it with this:

'+sessionServerId + '' + countryAssetsInternationalization+'&gameServer=https://webserver.com&gameAssets=';

I try a lot of possibilities with no results.

sed -i 's/\'\+sessionServerId \+ \'\' \+ countryAssetsInternationalization;/\'\+sessionServerId \+ \'\' \+ countryAssetsInternationalization\+\'\&gameServer=https:\/\/webserver.com&gameAssets=\';/g' index.jsp

Can you help me? Thank you!

SOLVED:

sed -i 's/\+ countryAssetsInternationalization;/\+ countryAssetsInternationalization\+'\''&gameServer=https:\/\/webserver.com\&gameAssets='\'';/g' index.jsp

Upvotes: 0

Views: 108

Answers (2)

Ivan Martinez
Ivan Martinez

Reputation: 39

I can solve my problem myself:

sed -i 's/\+ countryAssetsInternationalization;/\+ countryAssetsInternationalization\+'\''&gameServer=https:\/\/webserver.com\&gameAssets='\'';/g' index.jsp

Upvotes: 2

Dima Chubarov
Dima Chubarov

Reputation: 17169

I am afraid \ is not reliable as a quote character in sed. Replace \' and \+ with ['] and [+] and it seems to start working.

sed "s/['][+]sessionServerId [+] [']['] [+] countryAssetsInternationalization;/\'\+sessionServerId \+ \'\' \+ countryAssetsInternationalization\+\'\&gameServer=https:\/\/webserver.com&gameAssets=\';/g" index.jsp

Upvotes: 0

Related Questions