Use json2tsv and AWK instead of jq - localbin - leot's localbin (~/bin)
(HTM) hg clone https://bitbucket.org/iamleot/localbin
(DIR) Log
(DIR) Files
(DIR) Refs
---
(DIR) changeset 309ecd5e9cee65ae5744057a9badffbc548ad419
(DIR) parent d89c8ba3f6ba33c6fb3b8600008397756547adb7
(HTM) Author: Leonardo Taccari <iamleot@gmail.com>
Date: Fri, 18 Oct 2019 11:20:33
Use json2tsv and AWK instead of jq
Diffstat:
pispedizioni | 33 +++++++++++++++++++++++++++------
1 files changed, 27 insertions(+), 6 deletions(-)
---
diff -r d89c8ba3f6ba -r 309ecd5e9cee pispedizioni
--- a/pispedizioni Thu Oct 17 16:15:04 2019 +0200
+++ b/pispedizioni Fri Oct 18 11:20:33 2019 +0200
@@ -16,12 +16,33 @@
curl -H 'Content-Type: application/json;charset=UTF-8' \
-d "{ \"codiceSpedizione\": \"${pid}\", \"tipoRichiedente\": \"WEB\" }" \
-gs 'https://www.poste.it/online/dovequando/DQ-REST/ricercasemplice' |
- jq -r '
- .listaMovimenti[]? | (
- ((.dataOra / 1000) | localtime | strftime("%d/%m/%Y %H:%M")) + "\t" +
- .luogo + "\t" +
- .statoLavorazione
- )'
+ json2tsv | awk -F '\t' '
+ BEGIN {
+ bn = ".listaMovimenti[]"
+ }
+
+ $1 == bn {
+ n++
+ }
+ $1 == bn ".dataOra" {
+ events[n, "date"] = strftime("%d/%m/%Y %H:%M", $3 / 1000)
+ }
+
+ $1 == bn ".luogo" {
+ events[n, "location"] = $3
+ }
+
+ $1 == bn ".statoLavorazione" {
+ events[n, "status"] = $3
+ }
+
+ END {
+ for (i = 1; i <= n; i++) {
+ printf("%s\t%s\t%s\n", events[i, "date"],
+ events[i, "location"], events[i, "status"])
+ }
+ }
+'
}