0

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.

6
  • 1
    Welcome to U&L. I probably won't be the only one to ask that you supply some example input and together with desired output.
    – steve
    Commented Sep 25, 2019 at 20:15
  • Array 1 content1, content2, primaryKey1, content1, content1 content2, content2, primaryKey2, content2, content2 content3, content3, primaryKey3, content3, content3 Array 2 data1, data2, primaryKey1, data1, data1 data3, data3, primaryKey3, data3, data3 datat2, data2, primaryKey2, data2, data2 Output content1, content2, primaryKey1, content1, content1 data1, data2, primaryKey1, data1, data1 content2, content2, primaryKey2, content2, content2 datat2, data2, primaryKey2, data2, data2 content3, content3, primaryKey3, content3, content3 data3, data3, primaryKey3, data3, data3
    – Kwesi
    Commented Sep 25, 2019 at 20:41
  • Not sure if my reply was format correctly. I am not familiar on how to use this tool so my apologies.
    – Kwesi
    Commented Sep 25, 2019 at 20:42
  • 3
    @Kwesi, edit your original question, and ass the example there (as then the formatting will be retained).
    – boardrider
    Commented Sep 25, 2019 at 21:34
  • @Kwesi, are you sure that AWK is the right tool for the job? A bash script (which may use AWK), or a python script, seem like more suitable tools for this problem.
    – boardrider
    Commented Sep 25, 2019 at 21:36

1 Answer 1

0

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";
                    }

                }
            }

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .