super array v/vr

This commit is contained in:
olli 2024-08-24 12:58:12 +02:00
parent c761fe5d93
commit 2cdab60efb
2 changed files with 11 additions and 4 deletions

View File

@ -1,5 +1,5 @@
function g_basename { function g_basename {
g_basename_result="${1##*/}" g_basename_result=${1##*/}
g_basename_result="${g_basename_result:-/}" g_basename_result=${g_basename_result:-/}
} }

View File

@ -48,6 +48,10 @@ function g_read_csv {
g_csv_headline_array+=("${g_headline_item//[^a-zA-Z0-9_]/}") g_csv_headline_array+=("${g_headline_item//[^a-zA-Z0-9_]/}")
done done
g_basename $g_csvfile
local g_csvfile_base=${g_basename_result/\.history*.csv/}
g_csvfile_base=${g_csvfile_base//[^a-zA-Z0-9_]/}
# read last lines if defined or complete csv file # read last lines if defined or complete csv file
if [ -n "$g_last_lines" ] if [ -n "$g_last_lines" ]
then then
@ -55,14 +59,15 @@ function g_read_csv {
g_csvfile="${g_tmp}/g_csv_tmp.csv" g_csvfile="${g_tmp}/g_csv_tmp.csv"
fi fi
# read csv file to array # read csv file to array
g_array "$g_csvfile" g_csv_array_ref g_array "$g_csvfile" g_csv_array_ref
g_csv_array=("${g_csv_array_ref[@]}") g_csv_array=("${g_csv_array_ref[@]}")
# go reverse through array # create associative arrays forward and reverse and superarray v/vr
declare -Ag v_csv_array_associative declare -Ag v_csv_array_associative
declare -Ag v_csv_array_associative_reverse declare -Ag v_csv_array_associative_reverse
declare -Ag v
declare -Ag vr
l=0 l=0
for (( r=${#g_csv_array[@]}-1 ; r>=0 ; r-- )) for (( r=${#g_csv_array[@]}-1 ; r>=0 ; r-- ))
do do
@ -76,6 +81,8 @@ function g_read_csv {
[ "$l" = 0 ] && declare -g v_${g_headline_item}="${g_csv_line_array[i]}" [ "$l" = 0 ] && declare -g v_${g_headline_item}="${g_csv_line_array[i]}"
v_csv_array_associative[${g_headline_item}_${r}]="${g_csv_line_array[i]}" v_csv_array_associative[${g_headline_item}_${r}]="${g_csv_line_array[i]}"
v_csv_array_associative_reverse[${g_headline_item}_${l}]="${g_csv_line_array[i]}" v_csv_array_associative_reverse[${g_headline_item}_${l}]="${g_csv_line_array[i]}"
v[${g_csvfile_base}_${g_headline_item}_${r}]=${g_csv_line_array[i]}
vr[${g_csvfile_base}_${g_headline_item}_${l}]=${g_csv_line_array[i]}
((i++)) ((i++))
done done
((l++)) ((l++))