#!/bin/csh -f

if ( $#argv != 3) then
  echo "Usage: replace_in_html.csh <parent_dir> <search_for_phrase> <replace_with_phrase>"
  exit
endif

set parent_dir = $argv[1]
set old_phrase = $argv[2]
set new_phrase = $argv[3]

set files = `find $parent_dir -name "*.*"`

foreach filename ($files)

  ###### Check if *html contains mems-cmu

#  set html_check = `awk '/'${old_phrase}'/{printf "+"}' ${filename}`
#  echo -n ""

#  if (${html_check} != "") then
    echo "Replacing $old_phrase with $new_phrase in file $filename"
    cat ./$filename | sed "s^$old_phrase^$new_phrase^g" > ./$filename.tmp
    mv ./$filename.tmp ./$filename
#  endif

end
