Des scripts pour imprimer les données dans TSV sous la forme d'un layout prédéfini - retour accueil
git clone git://bebou.netlib.re/tsv2layout
Log | Files | Refs | README |
commit fd970e0d4a3f750648e4da81b445055750ef3170 Auterice: Arthur Pons <arthur.pons@unistra.fr> Date: Wed, 11 Sep 2024 15:51:48 +0200 Ajout de quatre variantes Diffstat:
A | README | | | 3 | +++ |
A | tsv2layout | | | 12 | ++++++++++++ |
A | tsv2layout.awk | | | 13 | +++++++++++++ |
A | tsv2layout.printf1 | | | 12 | ++++++++++++ |
A | tsv2layout.printf2 | | | 23 | +++++++++++++++++++++++ |
5 files changed, 63 insertions(+), 0 deletions(-)
diff --git a/README b/README @@ -0,0 +1,3 @@ +Diverses implémentation de tsv2layout + +Juste pour pas les perdre diff --git a/tsv2layout b/tsv2layout @@ -0,0 +1,12 @@ +#! /bin/sh + +tmpd=$(mktemp -d) +cat | + tee $tmpd/all | + head -n1 | + tr ' ' '\n' > $tmpd/vars +tail -n+2 $tmpd/all | +while read line;do + eval $(echo "$line" | tr ' ' '\n' | paste -d '=' $tmpd/vars - | sed -E "s/=/&'/;s/$/'/") + . ./layout +done diff --git a/tsv2layout.awk b/tsv2layout.awk @@ -0,0 +1,13 @@ +#! /bin/sh + +awk -F '\t' ' +BEGIN { getline; split($0,vars) } +NR!=1 { + split($0,line); + for (i=1;i<8;i++) { + printf "%s=\"%s\"\n", vars[i], line[i] + } + print ". ./layout" +} +' + diff --git a/tsv2layout.printf1 b/tsv2layout.printf1 @@ -0,0 +1,12 @@ +#! /bin/sh + +awk -F '\t' ' +BEGIN { getline; split($0,vars) } +NR!=1 { + split($0,line); + for (i=1;i<8;i++) { + printf "%s=\"%s\"\n", vars[i], line[i] + } +} +' + diff --git a/tsv2layout.printf2 b/tsv2layout.printf2 @@ -0,0 +1,23 @@ +#! /bin/sh + +tmpd=$(mktemp -d) + +layout=$(< $1 sed -E 's/\$[a-zA-Z]+/%s/g') +nbargs=$(echo "$layout" | grep -o '%s' | wc -l) +maxargs=$(echo "4096/$nbargs*$nbargs" | bc) + +cat > $tmpd/in + +< $tmpd/in head -n1 | tr ' ' '\n' | nl -n ln -w1 > $tmpd/vars + +for var in $(< $1 grep -wEo '\$[a-zA-Z]+' | tr -d '$');do + grep "$var" $tmpd/vars +done | + cut -f1 | paste -s -d',' | + xargs -I{} awk -F'\t' -v col={} ' + BEGIN{getline;split(col,cols,",")} + { for (i=1;i<5;i++) { print $cols[i] } }' $tmpd/in | + xargs -d'\n' -n$maxargs printf "$layout\n" + +rm -rf $tmpd +