×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

sed substitution within bash script with mixed quotes

sed substitution within bash script with mixed quotes

sed substitution within bash script with mixed quotes

(OP)
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:

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

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.

RE: sed substitution within bash script with mixed quotes

Hi

CODE --> command line

/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 --> command line

/usr/bin/sed -i -f transform-my-code.sed /home/impact/php_repair_temp/*.php 

CODE --> transform-my-code.sed

s/(session_is_registered('ADMIN')/$_SESSION["group_code"]=='ADMIN'/g 

Feherke.
feherke.github.io

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close