I'm trying to match up the data from an array the lists the days of the week like this:MONDAYTUESDAYWEDNESDAYTHURSDAYFRIDAYSATURDAYSUNDAYThe files data reads like this:Name1,TuesdayName2,FridayName3,SundayName4,WednesdayName5,ThursdayName6,SaturdayThe output should be:MONDAY TUESDAY Name1WEDNESDAY Name4THURSDAY Name5FRIDAY Name2SATURDAY Name6SUNDAY Name3I am able to cut the data by the comma into two. I was wondering if it's possible to match the data from the file to the data within the array.
Match data from array to data from file?
awk;array;cut
If file1 has the days of the week and file2 has the days and names, then:$ awk -F, 'FNR==NR{a[toupper($2)]=$1;next} {print $1,a[$1]}' file2 file1MONDAY TUESDAY Name1WEDNESDAY Name4THURSDAY Name5FRIDAY Name2SATURDAY Name6How it works-F,Use a comma as the field separator.FNR==NR{a[toupper($2)]=$1;next}While we are reading through the first named file, file2, add an entry to associative array a with the key as the upper case version of the day and value as the name.  Then, skip the rest of the commands and jump to the next line.print $1,a[$1]If we get to here, we are working on the second file.  In that case, print the day and the name that we retrieve from associative array a.