find and replace

find and replace

Post by Matthew Bu » Mon, 02 Sep 1996 04:00:00



i have a lot of HTML files with the code
<body bgcolor=white>

i would like to change this line to
<body bgcolor=FFFFFF>

the files are dispersed in a variety of directories...is there
a way to find and replace the "white" for "FFFFFF" in all these
files? i heard it could be done with the sed command somehow??

help is very much appreciated.

thanks,matt

 
 
 

find and replace

Post by William Edward Webb » Tue, 03 Sep 1996 04:00:00



:
: i have a lot of HTML files with the code
: <body bgcolor=white>
:
:
: i would like to change this line to
: <body bgcolor=FFFFFF>
:
: the files are dispersed in a variety of directories...is there
: a way to find and replace the "white" for "FFFFFF" in all these
: files? i heard it could be done with the sed command somehow??
:
With apologies to _real_ shell programmers, the following script
should do the trick:

#!/bin/bash
for dir in <list full path names of all html directories here>; do
   cd $dir
   for afile in $(ls); do
      if [ -f $afile ] && grep -q '<body bgcolor=white>' $afile; then
         sed 's/<body bgcolor=white>/<body bgcolor=FFFFFF>/g' > $afile.temp
         mv $afile.temp $afile
      fi
   done
done

No warranties, mind...
--
William Webber                  Postgrad. Dip. in CS, RMIT, Australia

"Well, I'll say this for you, the quality of your stupidity is rising"
                                        - Lucy, from Peanuts.

 
 
 

find and replace

Post by Marcus Danie » Tue, 03 Sep 1996 04:00:00




Quote:>i have a lot of HTML files with the code
><body bgcolor=white>
>i would like to change this line to
><body bgcolor=FFFFFF>

>the files are dispersed in a variety of directories...is there
>a way to find and replace the "white" for "FFFFFF" in all these
>files? i heard it could be done with the sed command somehow??

I cannnot tell who the command line to do it, because I never learned to use
those tools, but its a classic UNIX problem.

Maybe you want to use "find" to find all the html files and upon finding
them to execute "sed" with the appropriate regular expression to do the
search and replace.

I really should leaarn to handle regular expressions and to use sed <sigh>.

Bye
   Marcus

--

-------------------------------------------