File: xml_insert.sh

package info (click to toggle)
gegl 0.0.18-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 6,784 kB
  • ctags: 4,389
  • sloc: ansic: 45,496; sh: 9,223; ruby: 1,361; makefile: 740; cpp: 509; xml: 256
file content (29 lines) | stat: -rwxr-xr-x 829 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/sh
#
# Utility script to merge an xml snippet from one file into a document.
#
# To insert the file foo.inc into bar.xml,
# after the first line containing the marker <!--foo--> enter
#
# xml_insert.sh bar.xml foo foo.inc
#
# adding yet another argument will encode <,> and & as html entites.
#
# 2005 © Øyvind Kolås
#
# FIXME: add argument checking / error handling

which tempfile > /dev/null && TMP_FILE=`tempfile` || TMP_FILE="/tmp/temp_file"

cp $1 $TMP_FILE

SPLIT=`grep -n "<\!--$2-->" $TMP_FILE|head -n 1 | sed -e "s/^[  ]*//" |sed -e "s/:.*//"`;
head -n $SPLIT $TMP_FILE > $1
if [ -z "$4" ]; then
  cat $3 >> $1
else
  cat $3 | sed -e "s/\&/\&amp;/g" -e "s/</\&lt;/g" -e "s/>/\&gt;/g" >> $1
fi
tail -n $((`wc -l $TMP_FILE | sed -e "s/^[      ]*//" | sed -e "s/ .*//"` - $SPLIT )) $TMP_FILE >> $1

rm $TMP_FILE