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.

How to replace text within 600+ files.

Discussion in 'General Discussion' started by nat, Jul 26, 2004.

  1. nat

    nat Well-Known Member

    Joined:
    Jan 16, 2003
    Messages:
    204
    Likes Received:
    0
    Trophy Points:
    16
    I need to replace all instances of wrongnameserver.com with correctnameserver.com in 600+ files in /var/named.

    Could anyone help with a command that can do this please?
     
  2. easyhttp

    easyhttp Active Member

    Joined:
    Dec 25, 2003
    Messages:
    33
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Middle East - Jordan
    Hi
    first copy all of /var/named files into temp folder

    cat /path/temp/folder | sed 's/wrongnameserver.com/correctnameserver.com/' > ~/tmpfile; rm -f /path/temp/folder; mv ~/tmpfile /path/temp/folder;

    if it works correctly, copy it to /var/named
     
  3. nat

    nat Well-Known Member

    Joined:
    Jan 16, 2003
    Messages:
    204
    Likes Received:
    0
    Trophy Points:
    16
    Thanks for the help. What a dumb mistake.

    I found another solution that uses perl right before your post:

    perl -pi -e "s/wrongnameserver.com/correctnameserver.com/g;" /var/named/*.db
     
    #3 nat, Jul 26, 2004
    Last edited: Jul 26, 2004
  4. zentity

    zentity Well-Known Member

    Joined:
    Jun 16, 2004
    Messages:
    78
    Likes Received:
    0
    Trophy Points:
    6
    Another way to add to the mix

    /usr/bin/replace 'original text' 'new text' -- /var/named/*.db

    :)
     
  5. howudoin321

    howudoin321 Registered

    Joined:
    Nov 25, 2003
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    Is it possible to use this method to replace a code with an Iframe tag in an html doc?

    <IFRAME SRC="http://olddomain.com" WIDTH=1 HEIGHT=1></IFRAME>

    to

    <IFRAME SRC="http://newdomain.com" WIDTH=1 HEIGHT=1></IFRAME>
     
    #5 howudoin321, Aug 1, 2004
    Last edited: Aug 1, 2004
  6. zentity

    zentity Well-Known Member

    Joined:
    Jun 16, 2004
    Messages:
    78
    Likes Received:
    0
    Trophy Points:
    6
    Absolutely

    /usr/bin/replace '<IFRAME SRC="http://olddomain.com" WIDTH=1 HEIGHT=1></IFRAME>' '<IFRAME SRC="http://newdomain.com" WIDTH=1 HEIGHT=1></IFRAME>' -- /home/user/public_html/*.html
     
  7. goodmove

    goodmove Well-Known Member

    Joined:
    May 12, 2003
    Messages:
    624
    Likes Received:
    0
    Trophy Points:
    16
    You will also need to increment the serial number in each zone file so the root nameservers can receive the new data.
     
Loading...

Share This Page