#! /bin/tcsh -f # See the Usage block for comments. set me=$0:t # the name of this program goto Start ###################################################################### Usage: cat << END_INPUT Usage: $me chunk_file THE_TAG html_file Inserts the contents of chunk_file between matched pairs of tags in an html_file. chunk_file : A file containing the chunk of text to be inserted html_file : An HTML file containing a matched pair of tags THE_TAG : An alpha_numeric string tag that marks the places in the HTML file where the chunk will be inserted. Example: If THE_TAG is "OFFLINE" then this script will search for code in the HTML file that looks like this: ... (other html code) ... All the text between the tags will be replaced by the contents of the chunk file. The tag lines must be on separate lines (i.e., not inline). END_INPUT exit ###################################################################### Start: if ($# < 3) then goto Usage endif set theChunkFile="$1" set theTagBase="$2" set theFile="$3" if (! -e $theChunkFile) then echo "${me}: Can't find chunk file \'$theChunkFile\'." goto Usage endif if (! -e $theFile) then echo "${me}: Can't find HTML file \'$theFile\'." goto Usage endif set startTag = "<\!--_${theTagBase}_START_-->" set endTag = "<\!--_${theTagBase}_END_-->" grep -q $startTag $theFile # look for the START tag if ($status) then echo "${me}: Can't find start tag '$startTag'." goto Usage endif grep -q $endTag $theFile # look for the END tag if ($status) then echo "${me}: Can't find end tag '$endTag'." goto Usage endif # edit the file ed -s $theFile << END_INPUT /$startTag/+1,/$endTag/-1 d /$startTag/r $theChunkFile w Q END_INPUT