1
0
Fork 0
mirror of https://github.com/notwa/rc synced 2024-11-09 19:09:04 -08:00
rc/sh/slitt
Connor Olding d5f3f14d72 merge compatibility lines
RIP meaningful last-modified dates
2024-03-26 15:08:14 -07:00

22 lines
703 B
Bash
Executable file

#!/usr/bin/env dash
# YES_ZSH YES_BASH YES_DASH YES_ASH
# works with busybox ash.
slitt() { ### @-
### view specific columns of text.
### this version of `slit` uses tabs for its field separators.
[ $# -gt 0 ] \
|| { printf '%s: too few arguments\n' "$0" >&2; return 1; }
local arg=
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:,:):-\$${^@}} }"
}
[ -n "${preload+-}" ] || slitt "$@"