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!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Find & Replace in Files

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

  1. davetanguay

    davetanguay Active Member

    Joined:
    Mar 30, 2008
    Messages:
    26
    Likes Received:
    0
    Trophy Points:
    51
    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/
     
    #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,447
    Likes Received:
    56
    Trophy Points:
    28
    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..
     
  3. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    38,165
    Likes Received:
    1,371
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
Loading...

Share This Page