1
0
Fork 0
mirror of https://github.com/notwa/rc synced 2024-11-14 08:59:03 -08:00
rc/sh/slitt

23 lines
703 B
Text
Raw Normal View History

#!/usr/bin/env dash
# YES_ZSH YES_BASH YES_DASH YES_ASH
2021-09-23 06:48:05 -07:00
# works with busybox ash.
2021-07-29 00:37:35 -07:00
2021-07-30 17:57:08 -07:00
slitt() { ### @-
### view specific columns of text.
### this version of `slit` uses tabs for its field separators.
2021-10-01 12:40:27 -07:00
[ $# -gt 0 ] \
|| { printf '%s: too few arguments\n' "$0" >&2; return 1; }
local arg=
2021-10-01 12:40:27 -07:00
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:,:):-\$${^@}} }"
2021-07-29 00:37:35 -07:00
}
[ -n "${preload+-}" ] || slitt "$@"