ste

Једноставни уређивач табела
Дневник | Датотеке | Референце | ПРОЧИТАЈМЕ | ЛИЦЕНЦА

чување ebfb22d88354fd3c9bc01ccee6560af242a710cc
родитељ f80dc2159c0df204746156b09bd714ed2fcb817b
Аутор: Страхиња Радић <contact@strahinja.org>
Датум:   Tue, 11 Jul 2023 16:29:10 +0200

Bugfix: Add missing transpose script; update prerequisites and comments

Signed-off-by: Страхиња Радић <contact@strahinja.org>

Diffstat:
MINSTALL | 4++--
Minstall.do | 2+-
Atranspose | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mtsvdel | 3+++
Mtsvedit | 3+++
Mtsvins | 3+++
Muninstall.do | 2+-
измењених датотека: 7, додавања: 68(+), брисања: 4(-)

diff --git a/INSTALL b/INSTALL @@ -2,8 +2,8 @@ Prerequisites ============= * gzip -* Standard utilities: cat, cp, diff, getopts, grep, head, mv, printf, rm, sed, - stat, tail, touch, wc +* Standard utilities: awk, cat, cp, cut, diff, getopts, grep, head, mv, printf, + rm, sed, stat, tail, touch, trap, wc * table[1] * vipe from moreutils[2] * Any text editor set via EDITOR environment variable diff --git a/install.do b/install.do @@ -11,7 +11,7 @@ MANDIR=$PREFIX/share/man/man1 # install -Dm 0644 "${docfile}" "${DOCDIR}/${docfile}" #done install -d $BINDIR $MANDIR -for binfile in ste tsvdel tsvins tsvedit; do +for binfile in ste transpose tsvdel tsvins tsvedit; do install -m 0755 "${binfile}" "${BINDIR}/${binfile}" done install -m 0644 ste.1.gz "${MANDIR}/ste.1.gz" diff --git a/transpose b/transpose @@ -0,0 +1,55 @@ +#!/bin/sh +# vim: set ft=bash: +# transpose - Transpose a TSV file +# See the file LICENSE for copyright and license details. + +if [ $# -lt 1 ] || [ "$1" = "-h" ] +then + cat <<! >&2 +Usage: ${0##*/} [file] +! + exit 1 +fi + +tmpf=/tmp/transpose.$$ +tmpf_complete=/tmp/transpose.$$.complete +active=1 +colno=1 +input=$1 + +cat "$input" >$tmpf + +trap "rm -f \"$tmpf\" \"$tmpf_complete\"" HUP PIPE INT QUIT TERM EXIT + +# Fix lines without the necessary number of tabs +firstline=1 +while read -r line; do + ntabs=$(echo "$line" | sed 's/[^\t]\+//g' | wc -c) + if [ $firstline -eq 1 ]; then + firstline=0 + if [ "$ntabs" -ge 1 ]; then + max_tabs=$((ntabs-1)) + else + max_tabs=0 + fi + fi + printf "%s" "$line" + i=$((max_tabs-ntabs+1)) + while [ "$i" -gt 0 ]; do + printf '\t' + i=$((i-1)) + done + echo +done < "$tmpf" > "$tmpf_complete" + +while [ $active -eq 1 ] +do + cut -f$colno $tmpf_complete | paste -s + colno=$(( colno + 1 )) + if [ $max_tabs -eq 0 ] || \ + [ -z "$(cut -f${colno}- $tmpf_complete | sed -z 's/\n//g')" ] + then + active=0 + fi +done +rm -f $tmpf $tmpf_complete diff --git a/tsvdel b/tsvdel @@ -1,4 +1,7 @@ #!/bin/sh +# vim: set ft=bash: +# tsvdel - Delete a line from a TSV file +# See the file LICENSE for copyright and license details. usage() { diff --git a/tsvedit b/tsvedit @@ -1,4 +1,7 @@ #!/bin/sh +# vim: set ft=bash: +# tsvedit - Edit a line from a TSV file +# See the file LICENSE for copyright and license details. # Needs vipe from moreutils and $EDITOR https://joeyh.name/code/moreutils/ diff --git a/tsvins b/tsvins @@ -1,4 +1,7 @@ #!/bin/sh +# vim: set ft=bash: +# tsvins - Insert a line to a TSV file +# See the file LICENSE for copyright and license details. # Needs vipe from moreutils and $EDITOR https://joeyh.name/code/moreutils/ diff --git a/uninstall.do b/uninstall.do @@ -6,7 +6,7 @@ PREFIX=${PREFIX:-/usr/local} BINDIR=$PREFIX/bin #DOCDIR=$PREFIX/share/doc/ste MANDIR=$PREFIX/share/man/man1 -for binfile in ste tsvdel tsvins tsvedit; do +for binfile in ste transpose tsvdel tsvins tsvedit; do rm -f "${BINDIR}/${binfile}" done rm -f "${MANDIR}/ste.1.gz"