I have two arrays. I need to loop through array 1 a row at a time. For each row in array 1 there are transactional records in array 2. I need to print the transactional record for each row in array 1 that matches on a primary key shared between the two array. So think of it like a bank account. Array 1 have 6 account and array 2 has all the transaction for each account. How do I print to a file the account information in array 1 on the first follow by a line break then all the transaction for that account. Both file are using the account number to match records. I need to use "awk" in bash scripting.
1 Answer
I am not sure if awk or bash will accomplish my task. I am still trying to learn both. I appreciate any direction. I do have to use a Shell script so either bash or awk. I thought a nested for loop with a condition check on the main loop key will determine if the second loop will print transaction records.
for (key in Authorization_Arr)
{
print "SASH1" Authorization_Arr[key] > "output.csv"
for (i in LineItem_Arr)
{
split(LineItem_Arr[i], a, ", ")
if (a[2] == key)
{
print LineItem_Arr[i] > "output.csv";
}
}
}
bash
script (which may use AWK), or apython
script, seem like more suitable tools for this problem.