scripts/awk
branchv_0
changeset 16 4e8fe4cc70f0
child 27 86d8bbc99e7b
equal deleted inserted replaced
15:ba91a464d2b3 16:4e8fe4cc70f0
       
     1 #!/bin/bash
       
     2 
       
     3 # Relational pipes
       
     4 # Copyright © 2019 František Kučera (Frantovo.cz, GlobalCode.info)
       
     5 #
       
     6 # This program is free software: you can redistribute it and/or modify
       
     7 # it under the terms of the GNU General Public License as published by
       
     8 # the Free Software Foundation, either version 3 of the License, or
       
     9 # (at your option) any later version.
       
    10 #
       
    11 # This program is distributed in the hope that it will be useful,
       
    12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
       
    14 # GNU General Public License for more details.
       
    15 #
       
    16 # You should have received a copy of the GNU General Public License
       
    17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
       
    18 
       
    19 
       
    20 # This is a simple helper script (/usr/bin/awk wrapper) for debugging the relpipe-tr-awk.
       
    21 # Captures STDIO and ARGS to log files.
       
    22 # Add this directory to the $PATH in order to use this wrapper script.
       
    23 #
       
    24 # Notes:
       
    25 #  - 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).
       
    26 #  - 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
       
    27 
       
    28 logDir="/tmp/relpipe-tr-awk/";
       
    29 
       
    30 mkdir -p "$logDir";
       
    31 
       
    32 formatArgsTxt() {
       
    33 	for a in "$@"; do
       
    34 		echo -e "\e[32m>>> arg >>>\e[39m"; # or use lolcat
       
    35 		echo "$a";
       
    36 		echo -e "\e[32m<<< arg <<<\e[39m";
       
    37 	done
       
    38 }
       
    39 
       
    40 formatArgsTabular() {
       
    41 	i=0;
       
    42 	for a in "$@"; do
       
    43 		echo "$a" | while read a; do
       
    44 			printf '%s\x0%s\x0' "$i" "$a";
       
    45 		done;
       
    46 		((i++));
       
    47 	done | relpipe-in-cli generate-from-stdin args 2 i integer value string | relpipe-out-tabular
       
    48 }
       
    49 
       
    50 formatArgsTxt "$@" > "$logDir/awk-args.log";
       
    51 
       
    52 tee "$logDir/awk-stdin.log" | /usr/bin/awk "$@" 2> "$logDir/awk-stderr.log" | tee "$logDir/awk-stdout.log";
       
    53 
       
    54 # Use e.g. GNU Screen with four windows to watch files:
       
    55 # watchFile() { while inotifywait "$1" &>/dev/null ; do clear; cat "$1" ; done; }
       
    56 # watchFile "/tmp/relpipe-tr-awk/awk-args.log"
       
    57 # watchFile "/tmp/relpipe-tr-awk/awk-stdin.log"
       
    58 # watchFile "/tmp/relpipe-tr-awk/awk-stdout.log"
       
    59 # watchFile "/tmp/relpipe-tr-awk/awk-stderr.log"