-
Notifications
You must be signed in to change notification settings - Fork 3
/
xml2csv.in
69 lines (61 loc) · 1.01 KB
/
xml2csv.in
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/sh
# Set constants and defaults
NAME="xml2csv"
XSLTPROC="@XSLTPROC@"
CSVXSL="@pkgdatadir@/csv.xsl"
# Usage message
usage()
{
echo "Usage:" 1>&2
echo " ${NAME} [input.xml]" 1>&2
echo "Options:" 1>&2
echo " -h Show this help message and exit" 1>&2
}
# Log functions
log()
{
echo ${NAME}: ${1+"$@"} 1>&2
}
# Error function
errout()
{
log ${1+"$@"}
exit 1
}
# Bail on errors
set -e
# Parse flags passed in on the command line
while [ ${#} -gt 0 ]; do
case "$1" in
-h|--help)
usage
exit
;;
--)
shift
break
;;
-*)
echo "${NAME}: unrecognized flag \`${1}'" 1>&2
usage
exit 1
;;
*)
break
;;
esac
done
case "${#}" in
0)
INPUT_FILE="-"
;;
1)
INPUT_FILE="${1}"
;;
*)
usage
exit 1
;;
esac
# Run
exec "${XSLTPROC}" "${CSVXSL}" "${INPUT_FILE}"