Skip to content

Commit dc2b0d8

Browse files
committed
Allow specifying different delimiters for csvline.
1 parent ac86a8b commit dc2b0d8

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

bashlib/bashlib

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -547,15 +547,21 @@ iterate() (
547547
# _______________________________________________________________________
548548
# |__ CSV ____________________________________________________________|
549549
#
550-
# csv
550+
# csv [-d delimiter] [-D line-delimiter]
551551
#
552552
# Parse a line of input and write the CSV fields to the CSVLINE array.
553553
#
554554
csvline() {
555555
CSVLINE=()
556-
local line field quoted=0 delimiter=,
556+
local line field quoted=0 delimiter=, lineDelimiter=$'\n' c
557+
local OPTIND=1
558+
while getopts :d: arg; do
559+
case $arg in
560+
d) delimiter=$OPTARG ;;
561+
esac
562+
done
557563

558-
IFS= read -r line || return
564+
IFS= read -d "$lineDelimiter" -r line || return
559565
while IFS= read -rn1 c; do
560566
case $c in
561567
\")

0 commit comments

Comments
 (0)