This commit is contained in:
Emma Tebibyte 2022-11-06 23:44:52 -05:00
parent 47ea0c11e3
commit 025afa39f3

27
tomcat
View File

@ -7,28 +7,31 @@ argv2=$2
# check usage
if ! test -n "$argv1"; then
printf "Usage: %s [resource...]\n" "$0" 1>&2
printf "Usage: %s [TABLE.KEY[INDEX]] [FILE]\n" "$0" 1>&2
exit 64 # sysexits(3) EX_USAGE
fi
if ! test -e "$1"; then
printf "%s: %s: No such file or directory.\n" "$0" "$1" 1>&2
exit 66 # sysexits(3) EX_NOINPUT
fi
set -- $(printf "%s\n" "$argv2" | cut -d "." --output-delimiter=" " -f 1-)
PAIRS=$(printf "%s\n" "$(sed 's/[^"#]#\+.*//g' <"$argv1")" | awk "/^\[$1\]/{flag=1; next} /^\[/{flag=0} flag" - )
set -- $(printf "%s\n" "$argv1" | cut -d "." --output-delimiter=" " -f 1-)
ARR=$(printf "%s\n" "$2" | sed -n 's/.\+\[//p' | tr -d ']')
ARG=$(printf "%s\n" "$2" | sed 's/\[.*\]//g')
VAL=$(printf "%s\n" "$PAIRS" | sed -n "s/$ARG *= *//p" | sed 's/", "/","/g' | tr -d '[]' | sed 's/^ //g')
VAL=$(if test -e "$argv2"; then
argv2=$(sed 's/[^"#]#\+.*//g' <"$argv2")
else
argv2=$(printf "%s\n" "$argv2" | sed 's/[^"#]#\+.*//g')
fi
printf "%s\n" "$argv2" |\
awk "/^\[$1\]/{flag=1; next} /^\[/{flag=0} flag" - |\
sed -n "s/$ARG *= *//p" | sed 's/", "/","/g' | tr -d '[]' |\
sed 's/^ //g')
if test -n "$ARR"; then
VAL=$(printf "%s\n" "$VAL" | sed -n 's/,/\n/p' | tr -d '"' | head -n "$ARR" | tail -n 1)
printf "%s\n" "$VAL" | sed 's/,"/\n"/g' | tr -d '"' | head -n "$ARR" |\
tail -n 1
else
printf "%s\n" "$VAL" | tr -d '"'
fi
printf "%s\n" "$VAL"
exit 0