I have a variable that should match one of these IDs. I want to load this config file into an awk array, and then parse trhough it to find the record and then use the PathToDirectory to copy my file to it.
This is what I have:
awk -v ak2=$AK202 -F "," '{ configfile[NR] = $0 }
END { for(i = 1; i <= NR; i++) { if (configfile=ak2) print configfile } } ' $INPUTFILE
Any thoughts? My idea is to fill the array, and then compare my AK202 variable to the second column, store the third as the destination directory.
Hi, one of the niceties of awk is that it knows associative arrays. This means that you are not limited to the use of integers to use as an index.. So instead of NR you can use $2 as the index, which would save you a loop. But in addition, in this case you do not even need an array, since you can evaluate straight away, while processing the lines..
awk -v ak2="$AK202" -F, '$2==ak2' "$INPUTFILE"
is all it takes. This solution would be more efficient: