Hi,
I have a csv file which contains data that looks something like this:
Key1 Key2 Key3 New_Key1 New_Key2 New_Key3
102 30 0 - - -
102 40 1 30 40 50
102 50 2 40 50 30
103 12 0 - - -
103 15 1 12 15 12
I need to fill in New_Key1, New_Key2 and New_Key3 based on the existing data taken from column Key2 keeping Key1 as the reference. A set of values of Key2 can be mapped to Key1. Like we have 30, 40 and 50 are mapped to Key1=102. Using this I need to fill in for New_Key1, New_Key2 and New_Key3. Here for my first row the New_Key1, New_Key2 and New_Key3 need to be dashed out. The value of New_Key1 on the second row is same as the 1st value of Key2(old) and the value of New_Key3 will be same as the 3rd value of Key2(new future value). While the value of New_Key2 will be same as the current value of Key2. Similarly for the next set of rows mapping to the same Key1 the process needs to repeat. But there's one more thing to it...The last value of New_Key3 will be the same as the first value of Key2. I hope my explanation is not confusing.
I want to this the awk way..but i'm kind of stuck. It might need me to use many more commands than is required. Please help me out!!