Home > Net >  Need help to replace complex string with sed
Need help to replace complex string with sed

Time:05-24

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!

CodePudding user response:

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

CodePudding user response:

Using sed

$ sed -i s"|[0-9]\([^;]*\)|2\1 '\&gameServer=https://webserver.com\&gameAssets='|" index.jsp
string2="' sessionServerId   ''   countryAssetsInternationalization '&gameServer=https://webserver.com&gameAssets=';"
  • Related