#!/usr/bin/awk -f # Written by Michal Kosmulski # This script is hereby put in the public domain. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED # WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO # EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # # Usage: # replace-file-fragments template=template_file content_file > output_file # # Replace fragments of one file with corresponding fragments from a template # file. Parts to be replaced are marked with special tags. The tags used # by default are in form of HTML/XML comments, as one typical use is # editing HTML files. Some parts of the file are the content and vary from # file to file, while others, e.g. menus and page footers, are the same # in many documents and can be updated with this script whenever the template # changes. Of course, this can be much easier achieved using SSI; However, # sometimes SSI is not available. # # The meaning of default tags is as follows: Each tag is a HTML comment and # should start the line it is in. All text after the tag, up to the end of # line is ignored. Text located between and # tags in the content file is replaced by the corresponding block of text # located between and in the template file. # Lines not located between REPLACE and ENDREPLACE tags in content file # are copied verbatim to standard output, unless they start with # (such lines are ignored when they appear in either file). # # Example: # # --- template file --- # Some text # # Menu # This line is ignored # # Something # # --- and content file --- # Text # # # The menu will be inserted here # # Page content # # --- result in the following output --- # Text # # Menu # # Page content # # REPLACE tags are copied to output as to allow processing the result over # and over again, should the template change. BEGIN { ignore_regex="^[[:space:]]*