1
0
Fork 0
mirror of https://github.com/notwa/rc synced 2024-05-18 01:53:22 -07:00

check slit/slitt arguments

This commit is contained in:
Connor Olding 2021-10-01 12:40:27 -07:00
parent ff6489bff5
commit ac88e80c60
2 changed files with 13 additions and 5 deletions

View File

@ -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/

View File

@ -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<NF;i++)printf"$%s,",$(i);print"$"$NF}'
local fields="$(printf ',$%s' $@ | cut -b2-)"
awk "BEGIN { FS=\"\\t\"; OFS=\"\\t\" } { print $fields }"
[ $# -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 '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:,:):-\$${^@}} }"