jaq - json2tsv - JSON to TSV converter
(HTM) git clone git://git.codemadness.org/json2tsv
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
jaq (565B)
---
1 #!/bin/sh
2 flags=""
3 while [ $# -gt 0 ]; do
4 [ "$1" = "-n" -o "$1" = "-u" ] || break
5 flags="${flags} $1"
6 shift
7 done
8
9 if [ $# -le 0 ]; then
10 echo "usage: jaq [-n] [-u] <awk expressions...>" >&2
11 exit 1
12 fi
13 expr="$*"
14
15 # POSIX way to simulate -o pipefail if JSON data is invalid.
16 statusfile="$(mktemp)" || exit 1
17 trap -- "rm -f \"${statusfile}\"" "EXIT"
18 { json2tsv ${flags} -r -F '\x1f' -R '\x1e'; echo $? >"${statusfile}"; } | \
19 LC_ALL=C awk "BEGIN { FS = \"\x1f\"; RS = \"\x1e\" }${expr}"
20 statuscode="$(cat "${statusfile}" 2>/dev/null)$?"
21 [ "${statuscode}" = "00" ]