Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2002
    United Kingdom

    Bash script to recrusivly open files in a folder and replace text?

    Hey there,

    Does anyone know of a bash script that will go through files in a folder recursivly, opening each one, searching for a string and replacing it with a different string.

    For example.....

    our company uses a site which displays mobile phones to our sales staff so that they can read about phone functions ect (they sell phones)

    Now the phoblem is, we had 100+ staff hitting this site every day... sometimes 20 users at once.... all day

    The site blocked us, but they have agreed to let us download a copy of their site via wget recusive and save it on our intranet.

    Well, the site files come down fine.... but the problem is, they have a different url for images, than they do for html content, for example:

    html content:

    now i have got wget to download all the html files from the domain and replaced the with our intranet url, but for the images... all the paths to the images still point to

    now we want to replace to the url of the images on our intranet but i cant seem to do this with wget

    so i need to run a script on all the html files (around 500 files) and replace the path of the images

    any ideas?


  2. #2
    Join Date
    Jul 2003
    for F in `find /home/sites/ -type f -name '*.html' -print`; do mv $F $F.tmp ; sed 's/<title>Untitled Document<\/title>/<title> My New Site Title <\/title>/g' $F.tmp > $F ; rm $F.tmp ; done
    Here is one I used in the past for changing the title in html pages. With a few tweaks and different search path used for 'find' it should do what your looking for.



Posting Permissions

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