Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Find & Replace in Files

Discussion in 'General Discussion' started by davetanguay, Aug 26, 2017.

  1. davetanguay

    davetanguay Active Member

    Joined:
    Mar 30, 2008
    Messages:
    33
    Likes Received:
    1
    Trophy Points:
    56
    I understand I can use sed to find and replace data such as follows:

    grep -r -l -e 'something1' /home/user/public_html/* | xargs sed -i 's/something1/something2/g'

    But how do I replace string that contains forward slashes?

    For example, how would I replace the following?

    FIND: example.com/~user/
    REPLACE: example.org/
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
    #1 davetanguay, Aug 26, 2017
    Last edited by a moderator: Aug 26, 2017
  2. 24x7server

    24x7server Well-Known Member

    Joined:
    Apr 17, 2013
    Messages:
    1,878
    Likes Received:
    89
    Trophy Points:
    78
    Location:
    India
    cPanel Access Level:
    Root Administrator
    Hi,

    To use the forward slashes as it is, you have to escape it with the backward slash..
    "\/" like this..
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. cPanelMichael

    cPanelMichael Technical Support Community Manager
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    44,803
    Likes Received:
    1,898
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Twitter:
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice