diff --git a/sh/slit b/sh/slit index 6a1b2e1..c219002 100755 --- a/sh/slit +++ b/sh/slit @@ -8,7 +8,12 @@ slit() { ### @- ### view specific columns of text. - [ $# -gt 0 ] || { printf "%s\n" "$0: too few arguments" >&2; return 1; } + [ $# -gt 0 ] \ + || { printf '%s: too few arguments\n' "$0" >&2; return 1; } + for arg; do + [ "$arg" -ge 0 ] 2>/dev/null \ + || { printf '%s: not a nonnegative integer: %s\n' "$0" "$arg"; return 1; }; + done awk "{ print $(printf ',$%s' $@ | cut -b2-) }" # via: https://github.com/sorin-ionescu/prezto/ diff --git a/sh/slitt b/sh/slitt index 9e2a351..a5ab55a 100755 --- a/sh/slitt +++ b/sh/slitt @@ -9,10 +9,13 @@ slitt() { ### @- ### view specific columns of text. ### this version of `slit` uses tabs for its field separators. - [ $# -gt 0 ] || { printf "%s\n" "$0: too few arguments" >&2; return 1; } - #echo "$@" | awk '{for(i=1;i&2; return 1; } + for arg; do + [ "$arg" -ge 0 ] 2>/dev/null \ + || { printf '%s: not a nonnegative integer: %s\n' "$0" "$arg"; return 1; }; + done + awk 'BEGIN { FS="\t"; OFS="\t" }'\ "{ print $(printf ',$%s' $@ | cut -b2-) }" # via: https://github.com/sorin-ionescu/prezto/ #awk "BEGIN { FS=\"\\t\"; OFS=\"\\t\" } { print ${(j:,:):-\$${^@}} }"