I have a properties file and wanted to read line by line and split each line into a array. I referenced Split string into an array in Bash and the awk statement looks complicated. In the same time I wanted to follow suggestion provided in the link. When I try the command in bash shell:
export $line1="table1;/users/user_name/dir1/dir2;/users/user_name/dirA/dirB"
readarray -td; a <<<"$line1,"; unset 'a[-1]'; declare -p a;
throws error.
bash: readarray: -d: invalid option
readarray: usage: readarray [-n count] [-O origin] [-s count] [-t] [-u fd] [-C callback] [-c quantum] [array]
Couldn't under the below awk statements:
array=()
while read -r -d $'\0' each; do # use a NUL terminated field separator
array+=("$each")
done < <(printf "%s" "$str" | awk '{ gsub(/,[ ]+|$/,"\0"); print }')
declare -p array
to translate to my requirement.
This is how I read the file:
while read record_line; do
if [ ! -z "$record_line" -a "$record_line" != " " ]; then
readarray -td; a <<<"$record_line,"; unset 'a[-1]'; declare -p a;
fi
done<${PPROPERTIES_FILE}
Any help. Thanks.