Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sed substitution within bash script with mixed quotes

Status
Not open for further replies.

admoore

IS-IT--Management
May 17, 2002
224
US
I am trying to update some legacy php code via some sed substitutions running in a bash script.
Some items seem to work fine; others not so much. The issue appears to be when the substitution strings contain single or double quotes.
I have tried a variety of means of escaping the quotes; but, have had no success.
Here is an example line from my bash script:

[pre]/usr/bin/sed -i 's/(session_is_registered('ADMIN')/$_SESSION["group_code"]=='ADMIN'/g' /home/impact/php_repair_temp/*.php[/pre]

I wish to replace: session_is_registered('ADMIN')
With: $_SESSION["group_code"]=='ADMIN'

Other substitutions without quotes in the string are working fine...

TIA,
-Allen M.
 
Hi

Code:
/usr/bin/sed -i 's/(session_is_registered('"'"'ADMIN'"'"')/$_SESSION["group_code"]=='"'"'ADMIN'"'"'/g' /home/impact/php_repair_temp/*.php

Alternatively you can just move the Sed code to a Sed script file to avoid shell quoting problems :
Code:
/usr/bin/sed -i -f transform-my-code.sed /home/impact/php_repair_temp/*.php
Code:
s/(session_is_registered('ADMIN')/$_SESSION["group_code"]=='ADMIN'/g


Feherke.
feherke.github.io
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top