Find the answer to your Linux question:
Results 1 to 4 of 4
I was wondering if it was possible to use SED to replace a string of the form: $_POST['variable'] with getVar('variable') ? I have tried a few expressions with no success. ...
  1. #1
    Just Joined!
    Join Date
    Nov 2008
    Posts
    2

    Cool A Basic SED question.

    I was wondering if it was possible to use SED to replace a string of the form:

    $_POST['variable'] with getVar('variable') ? I have tried a few expressions with no success. Any help would be greatly appreciated.

  2. #2
    Linux User
    Join Date
    May 2008
    Location
    NYC, moved from KS & MO
    Posts
    251
    how about
    echo -e "\$_POST['variable']" | sed -e "s#\$_POST\['variable'\]#getVar('variable')#g"

  3. #3
    Just Joined!
    Join Date
    Nov 2008
    Posts
    2
    I actually replaced most of the instances of this manually. But I am still interested in the solution to this problem. I was unclear in the previous post. What i was looking for is $_POST['variable'] replaced with getVar('variable') , where 'variable' is itself non-constant through out the file. I am just using 'variable' as a place-holder for any term there. I was able to replace $_POST[ with getVar( but how does one match and replace that last bracket with a parenthesis?

  4. #4
    Linux User
    Join Date
    May 2008
    Location
    NYC, moved from KS & MO
    Posts
    251
    Replace the sed part with
    sed -e "s#\$_POST\[\(.*\)]#getVar(\1)#g"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...