1
0
dotfiles/.config/zsh/lib/csv.zsh

34 lines
527 B
Bash
Raw Normal View History

2024-03-04 15:35:55 +03:00
#!/bin/zsh
## NB: set IFS manually
z-csv-select() {
local field value
field="${1:?}" value="${2:?}"
local line
local -a ary
while IFS='' read -rs line ; do
[ -n "${line}" ] || continue
ary=()
read -rs -A ary <<< "${line}"
[ "${ary[${field}]}" = "${value}" ] || continue
printf '%s' "${line}"
return 0
done
return 1
}
z-csv-field() {
local field
field="${1:?}"
local -a ary
read -rs -A ary
printf '%s' "${ary[${field}]}"
}