tab-delineated arrays when no index is specified

This commit is contained in:
Emma Tebibyte 2022-11-08 01:00:01 -05:00
parent b0435ca100
commit 09ba6c7644
1 changed files with 4 additions and 4 deletions

8
tomcat
View File

@ -38,19 +38,19 @@ fi
VAL=$(printf "%s\n" "$TOML" |\
# output only lines between TABLE and the next table
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
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')
# test if ARR is set; if it is, then we have an array index to grab
if test -n "$ARR"; then
# 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
else
# remove quotes and output VAL
printf "%s\n" "$VAL" | tr -d '"'
printf "%s\n" "$VAL"
fi
exit 0