tab-delineated arrays when no index is specified
This commit is contained in:
parent
b0435ca100
commit
09ba6c7644
8
tomcat
8
tomcat
@ -38,19 +38,19 @@ fi
|
|||||||
VAL=$(printf "%s\n" "$TOML" |\
|
VAL=$(printf "%s\n" "$TOML" |\
|
||||||
# output only lines between TABLE and the next table
|
# output only lines between TABLE and the next table
|
||||||
awk "/^\[$TABLE\]/{flag=1; next} /^\[/{flag=0} flag" - |\
|
awk "/^\[$TABLE\]/{flag=1; next} /^\[/{flag=0} flag" - |\
|
||||||
# remove the key from the string and concatenate arrays, removing
|
# remove the key from the string and delineate arrays, removing
|
||||||
# brackets, trailing commas, and leading spaces
|
# brackets, trailing commas, and leading spaces
|
||||||
sed -n "s/$KEY *= *//p" | sed 's/", "/","/g' | tr -d '[]' |\
|
sed -n "s/$KEY *= *//p" | sed 's/", "/ /g' | tr -d '[]"' |\
|
||||||
sed 's/, *$//g' | sed 's/^ *//g')
|
sed 's/, *$//g' | sed 's/^ *//g')
|
||||||
|
|
||||||
# test if ARR is set; if it is, then we have an array index to grab
|
# test if ARR is set; if it is, then we have an array index to grab
|
||||||
if test -n "$ARR"; then
|
if test -n "$ARR"; then
|
||||||
# change the line delineator to newlines for parsing and output the result
|
# change the line delineator to newlines for parsing and output the result
|
||||||
printf "%s\n" "$VAL" | sed 's/",/"\n/g' | tr -d '"' | head -n "$ARR" |\
|
printf "%s\n" "$VAL" | sed 's/ /\n/g' | head -n "$ARR" |\
|
||||||
tail -n 1
|
tail -n 1
|
||||||
else
|
else
|
||||||
# remove quotes and output VAL
|
# remove quotes and output VAL
|
||||||
printf "%s\n" "$VAL" | tr -d '"'
|
printf "%s\n" "$VAL"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
Loading…
Reference in New Issue
Block a user