Results 1 to 12 of 12
  1. #1
    Join Date
    Feb 2004
    Location
    Fort Worth, TX
    Posts
    2,585

    SSH or program how to file replace lots of files

    I think this would be the right forum but i'm not 100% sure. If not, Mods please move...

    I have anywhere between 80,000 - 90,000 webpages that have a single code into this. Unfortunately at the time the web developer I used didn't use PHP includes. So each .html file has the code in it.

    I want a way so I can do a single command either a program or an SSH command can find the syntax in the files and replace it will code I have. Its just a single line of code that is basically for an adsense code, so the pub-blahblahblah etc..

    Does anyone know of a SSH command I can use, or a program that will find and replace without manually opening up each file? 80k - 90k of opening files then find/replace will take forever!

    Thanks all!
    www.JGRoboMarketing.com / We Filter out the Bad Leads and Send you the Good ones!
    █ Office: (800) 959-0182 / Automated Lead Funnel Service

  2. #2
    Join Date
    Oct 2002
    Location
    Canada
    Posts
    3,100
    If you have mysql installed, you will have "replace" utility installed. Syntax is simple

    replace "from string" "to string" -- onefile anotherfile thirdfile ....

    For more info do "man replace". It goes without saying - make backup before doing this on many files

  3. #3
    Join Date
    Feb 2004
    Location
    Fort Worth, TX
    Posts
    2,585
    I found a really good Windows Search and Replace Utility that works across many different formats. I was able to Search and Replace over 92,349 files in less time that I took to reply to this thread.

    I was able to download it for free at: http://www.rjlsoftware.com/software/utility/search/

    So if anyone is looking to search and replace text with a bunch of files.. I strongly recommend this. This has saved me hours of work!

    Still looking for SSH command though... non-mysql.
    www.JGRoboMarketing.com / We Filter out the Bad Leads and Send you the Good ones!
    █ Office: (800) 959-0182 / Automated Lead Funnel Service

  4. #4
    Join Date
    Dec 2000
    Location
    The Woodlands, Tx
    Posts
    5,962
    http://www.laffeycomputer.com/rpl.html

    I use this on linux. Works great! It's fast too.

  5. #5
    Join Date
    Oct 2002
    Location
    Canada
    Posts
    3,100
    Quote Originally Posted by RealtorHost
    Still looking for SSH command though... non-mysql.

    There is no such thing as "SSH command". The "replace" I mentioned just comes as part of mysql package, it is not actual sql fuction, it is executable mysql folks use for some file operations and you can use it in your ssh session.

  6. #6
    Join Date
    Feb 2004
    Location
    Fort Worth, TX
    Posts
    2,585
    Quote Originally Posted by Webdude
    http://www.laffeycomputer.com/rpl.html

    I use this on linux. Works great! It's fast too.
    Cool, thanks for the link i'll check that out!


    sasha your saying there is no command in an ssh session for a file and/or replace? I know you can use pico/nano/vi etc.. to search and replace text within a single file.

    I would think there has to be a way to do a search replace in an ssh session. Most likely the post from Webdude is what I need... hmm...
    www.JGRoboMarketing.com / We Filter out the Bad Leads and Send you the Good ones!
    █ Office: (800) 959-0182 / Automated Lead Funnel Service

  7. #7
    Join Date
    Dec 2002
    Location
    chica go go
    Posts
    11,858
    Quote Originally Posted by sasha
    If you have mysql installed, you will have "replace" utility installed. Syntax is simple

    replace "from string" "to string" -- onefile anotherfile thirdfile ....

    For more info do "man replace". It goes without saying - make backup before doing this on many files
    or

    find . -iname '*.html' -exec replace "from string" "to string" -- {} \;

  8. #8
    Join Date
    Dec 2000
    Location
    The Woodlands, Tx
    Posts
    5,962
    Quote Originally Posted by RealtorHost
    Cool, thanks for the link i'll check that out!

    I would think there has to be a way to do a search replace in an ssh session. Most likely the post from Webdude is what I need... hmm...
    The way our systems work is each client has their own Apache conf file. One day I found I needed to change some text in all of them...... as you can imagine, not something I wanted to do one file at a time. On some searching, I cam across this nifty little program, and it worked perfect. It took it only a second or two to replace the text in hundreds of files.

    I have programs in Windows that do similar, but then, I didnt want to download all the files, change them, and upload them back up either. On the other hand, I am not familiar with the MySQL command sasha is talking about, but will most certainly check it out.

  9. #9
    Join Date
    Dec 2004
    Location
    New York, NY
    Posts
    10,574
    Quote Originally Posted by ub3r
    or

    find . -iname '*.html' -exec replace "from string" "to string" -- {} \;
    or

    replace "from string" "to string" -- *.html

  10. #10
    Join Date
    Dec 2002
    Location
    chica go go
    Posts
    11,858
    Quote Originally Posted by layer0
    or

    replace "from string" "to string" -- *.html
    Won't work if there are many files in the directory, also that won't execute recursively for files that are in subdirectories.

  11. #11
    Join Date
    Oct 2002
    Location
    State of Disbelief
    Posts
    22,948
    Seems a better fit in Technical issues than the lounge.

  12. #12
    Join Date
    Oct 2002
    Location
    Canada
    Posts
    3,100
    Quote Originally Posted by RealtorHost
    I would think there has to be a way to do a search replace in an ssh session. Most likely the post from Webdude is what I need... hmm...
    I did not say that . I said that there is very easy way to do that in your ssh session using utility called simply "replace", and i said that there is no thing called "ssh commands" (just corrected your semantics).

    When you establish your ssh session you have available "builtin" shell commands such are "cd" ,"echo" , "exit" , "dirs" , "alias" ... provided by bash shell (different shells could provide different sets of builtin commands) , and you might have access to linux command line tools and utilities such are "cp", "mv", "replace" and many more. Which additional tools you have depends on which software packages you have installed. "replace" utility is usually installed as part of installation of mysql package.

    Now with semantics off the way before you do something like this

    find . -iname '*.html' -exec replace "from string" "to string" -- {} \;

    You need to make sure you know what will happen. First make sure that only appropriate files will be affected

    In this example this will list all files that will be affected by your actions :
    find . -iname '*.html' -exec ls -l {} \;

    You can output that list in the file so you can easy review it:
    find . -iname '*.html' -exec ls -l {} \; > list.txt

    Once when you know which files will be affected you can do
    find . -iname '*.html' -exec replace "from string" "to string" -- {} \;

Posting Permissions

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