Parsing Array Name Value Pairs

AIX ksh server hosted by vendor

How to parse & process the other params in the array**?

If it will help, to make the array layout different(?), I'm not married to awk, and in fact for other scripts, similar & less complex (fewer iterations & parameters) the array was arranged & parsed with substring commands w/a simple do/done loop, and before I give up on awk I'm posting here...

please suggest diff array layout it will help(?); note: the name=value (NV) will be actual parameters, however the values are going to be variables some requiring updates by functions, so final NV past to sed to edit a parameter file e.g. name=$value, w/Each line of the array are parameters to be eval about ~16 times with slight variations found in each line of the array...

# first 4 [0-3] params...
arrParams=
set -A arrParms
arrParams[0]='tpName'='ACCESSTC','fq'='Weekly','pID'='000000010','pDt'='Wed','HP'='PHP-GA','Act'='1','fDt'='Wed','IncFt'='1'
arrParams[1]='tpName'='MAGBHHTH','fq'='Weekly','pID'='999083153','pDt'='Mon','HP'='PHP-GA','Act'='1','fDt'='00000000','IncFt'='0'
arrParams[2]='tpName'='AMLOG','fq'='Weekly','pID'='000000014','pDt'='Mon','HP'='PHC-CA','Act'='1','fDt'='00000000','IncFt'='0'
arrParams[3]='tpName'='VSP','fq'='Weekly','pID'='000000023','pDt'='Mon','HP'='PHP-GA','Act'='1','fDt'='00000000','IncFt'='0'
#Show Array
for p in ${arrParams[@]};do
echo $p
done

...then...

# the IFS lines were from prior Unix.com posts so if not needed le'meknow.
# show TP record (partial key) for array at this point a new command would be made using the other NV
oIFS="$IFS"; IFS=','
for p in ${arrParams[@]};do
echo $p | awk -F, '{row=$0; 	
	for(i=1;i<=NF;i++)
	{	#row_split_col=$i;
		if(substr($i,1,6) == "tpName"){
		TPName=substr($i,8,20)
		print
		}
  } 
}' 
done
IFS="$oIFS"

**Parse & process other params; e.g. pDt=Mon means cycle = Monday to Monday with prior Monday date using... datecalc -- Perderabo's date calculator 2002-03-04 and my own dw2dw function

So, how to catch the other NV pairs and set the $value by calling functions w/in awk?

this link seems close but I'm dull on syntax...

Well... I found a solution that provides the parse & loop for each NV as well as count of pairs w/in each... and while my above was onto exploiting more of awk I went with this...

# first 4 [0-3] params...
arrParams=
set -A arrParms
arrParams[0]='tpName'='ACCESSTC','fq'='Weekly','pID'='000000010','pDt'='Wed','HP'='PHP-GA','Act'='1','fDt'='Wed','IncFt'='1'
arrParams[1]='tpName'='MAGBHHTH','fq'='Weekly','pID'='999083153','pDt'='Mon','HP'='PHP-GA','Act'='1','fDt'='00000000','IncFt'='0'
arrParams[2]='tpName'='AMLOG','fq'='Weekly','pID'='000000014','pDt'='Mon','HP'='PHC-CA','Act'='1','fDt'='00000000','IncFt'='0'
arrParams[3]='tpName'='VSP','fq'='Weekly','pID'='000000023','pDt'='Mon','HP'='PHP-GA','Act'='1','fDt'='00000000','IncFt'='0'

i=0; oIFS="$IFS"; IFS=',';aNV=; set -A aNV;pnv=0
for p in ${arrParams[@]};do
	if [[ $t -eq 0 ]]; then
		echo 'p: '${arrParams[$pnv]}
		set -A aNV
		aNV=${arrParams[$pnv]}
		aCnt=$(echo "$aNV" | awk -F',' '{print NF}')
		echo 'aCnt: '$aCnt
		for x in ${aNV[@]};do
		echo 'x: '$x
		done
		pnv=$((pnv+=1))
		echo 'exec/eval here?'
	fi
	i=$((i+=1))
	t=$((i%8))
	aNV=
done
IFS="$oIFS"

The first clears a string variable or the 0 element of an array, the second declares an array that you don't use - typo?
Perhaps you want

unset arrParams
set -A arrParams

but the declaration is not required, and the unset is needed only to clear previous values.

To prevent unwanted field splitting and filename generation you should quote variables in command arguments and in @-lists.

for p in "${arrParams[@]}" ;do
echo "$p"
done

The echo is a command. In an assignment the quotes are not needed (but allowed).

oIFS=$IFS

The IFS variable, input field separator, has special meaning in the shell; it is used to split a for list into fields and to split fields in a read command.

I still don't know what you are after, but here is a commented variant that demonstrates how array splitting and field splitting works.

unset arrParams
arrParams[0]='tpName'='ACCESSTC','fq'='Weekly','pID'='000000010','pDt'='Wed','HP'='PHP-GA','Act'='1','fDt'='Wed','IncFt'='1'
arrParams[1]='tpName'='MAGBHHTH','fq'='Weekly','pID'='999083153','pDt'='Mon','HP'='PHP-GA','Act'='1','fDt'='00000000','IncFt'='0'
arrParams[2]='tpName'='AMLOG','fq'='Weekly','pID'='000000014','pDt'='Mon','HP'='PHC-CA','Act'='1','fDt'='00000000','IncFt'='0'
arrParams[3]='tpName'='VSP','fq'='Weekly','pID'='000000023','pDt'='Mon','HP'='PHP-GA','Act'='1','fDt'='00000000','IncFt'='0'

oIFS="$IFS"; IFS=','
# Loop over array members, no field splitting on IFS and no filename generation
for p in "${arrParams[@]}"; do
    echo "member <$p>"
    # Loop over an unquoted array member, split on IFS
    # This will also attempt filename generation on glob characters * ? [ ] unless suppressed with "set -f"
    for q in $p; do
      echo "item <$q>"
    done
done
IFS="$oIFS"

MadeInGermany - I think you understand the essence of my ask in your much clearer example :slight_smile:

re: unset - Thanks, for the clarification (for me anyway) solution/syntax

Not that it matters for my question ( you answered well), I was trying to employ awk (me thinking that it was well suited) and I only write one-two new scripts a year so my AIX/ksh learning is both task based and limited so ++thanks for weighing in...

I started my script at what for me was the more challenging DateCalc functions that these parameters control for and w/awk how to gather & call functions was not clear; At the command point most of the parameters need to be updated by function calls, fq=Weekly + pDt (process date) = Mon means last Monday to next, so I use Perderabo's date calculator 2002-03-04 and my dw2dw (dayweek-to-dayweek) functions to set for example...

pDt=20210111 (process start date)
fDt=20210118 (future date)

whereas not shown are some parameters, fq=Daily and pDt=Today, and also

fDt (call to function LDayofNxtMo) as value = 20210228

all of these are used to update (sed) a vendor's parameter file and then call their script/program for each Trading Partner (TP) w/in the loop writing to processing log as needed

Again ++Thanks,
JeffP...