# HG changeset patch # User František Kučera # Date 1557239892 -7200 # Node ID 4e8fe4cc70f0e1330626eafc75ab79f4571f3eae # Parent ba91a464d2b36a8270a42c97bba65c5a0c243206 awk wrapper script for debugging diff -r ba91a464d2b3 -r 4e8fe4cc70f0 scripts/awk --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scripts/awk Tue May 07 16:38:12 2019 +0200 @@ -0,0 +1,59 @@ +#!/bin/bash + +# Relational pipes +# Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + + +# This is a simple helper script (/usr/bin/awk wrapper) for debugging the relpipe-tr-awk. +# Captures STDIO and ARGS to log files. +# Add this directory to the $PATH in order to use this wrapper script. +# +# Notes: +# - if multiple relations are processed, only the last one will stay in the log files (can be solved by adding PID to the log path). +# - if no relations are processed by the AWK sub-process, the logs will stay unchanged from the last run, although relpipe-tr-awk was executed + +logDir="/tmp/relpipe-tr-awk/"; + +mkdir -p "$logDir"; + +formatArgsTxt() { + for a in "$@"; do + echo -e "\e[32m>>> arg >>>\e[39m"; # or use lolcat + echo "$a"; + echo -e "\e[32m<<< arg <<<\e[39m"; + done +} + +formatArgsTabular() { + i=0; + for a in "$@"; do + echo "$a" | while read a; do + printf '%s\x0%s\x0' "$i" "$a"; + done; + ((i++)); + done | relpipe-in-cli generate-from-stdin args 2 i integer value string | relpipe-out-tabular +} + +formatArgsTxt "$@" > "$logDir/awk-args.log"; + +tee "$logDir/awk-stdin.log" | /usr/bin/awk "$@" 2> "$logDir/awk-stderr.log" | tee "$logDir/awk-stdout.log"; + +# Use e.g. GNU Screen with four windows to watch files: +# watchFile() { while inotifywait "$1" &>/dev/null ; do clear; cat "$1" ; done; } +# watchFile "/tmp/relpipe-tr-awk/awk-args.log" +# watchFile "/tmp/relpipe-tr-awk/awk-stdin.log" +# watchFile "/tmp/relpipe-tr-awk/awk-stdout.log" +# watchFile "/tmp/relpipe-tr-awk/awk-stderr.log"