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:
parent
ff6489bff5
commit
ac88e80c60
7
sh/slit
7
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/
|
||||
|
|
11
sh/slitt
11
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<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:,:):-\$${^@}} }"
|
||||
|
|
Loading…
Reference in New Issue
Block a user