9.10. Examples: Reading specific columns from multiple files and concatenating them horizontally (in different columns).

Print the first column of file2.txt followed (horizontally) by the second column of file4.txt. As we learned in previous examples, the command awk '{print $1}' file2.txt will read and print the first column of file2.txt. Conversely, awk '{print $2}' file4.txt will read and print the second column of file4.txt.
You must use the following syntax to concatenate these two results horizontally:

$ paste <(awk '{print $1}' file2.txt) <(awk '{print $2}' file4.txt)
"AnonymizedID" SubjectGroup
"B11130912" Group1
"B11137244" Group1
"B11154534" Group2
"B11144100" Group3
"B11137244" Group3
"B12226566" Group2
"B11134987" Group2
"B11144345" Group1
"C11137159" Group2
"B11156453" Group3
"B11110676" Group3
"C11138929" Group3
"B11154532" Group3
"B11155267" Group3
"B11137120" Group3
"B33191224" Group3
"B11155267" Group1
"C11138999" Group2
"B11131605" Group1
"B11137784" Group1
"B11156098" Group1
"B11133232" Group1
"B11135292" Group1
"C11138912" MISSING
"B11150911" Group1
"B11152577" Group1
"B11156098" Group1
"B11133232"

Print the first column of file1.csv followed (horizontally) by the second column of file3.csv. Separate the columns with a comma. In this example, we use the same syntax as the example before, but remember that files file1.csv and file3.csv use comma as the column separator and you have to use the -F',' flag in the awk commands. Additionally, remember to use the flag -d ',' for the paste command in order to separate the pasted columns with a comma.

$ paste -d ',' <(awk -F',' '{print $1}' file1.csv) <(awk -F',' '{print $2}' file3.csv)
"Anonymized ID",Subject Group
"B33199522",MISSING
"B33199603",Group1
"B11137879",Group1
"B11144410",Group1
"B11110455",Group1
"B11135291",Group1
"B11153927",Group1
"B11177579",Group1
"B11177806",Group1
"B11157958",Group3
"B11110690",Group3
"B11152799",Group3
"B11154358",Group3
"B11110925",Group2 b
"B11135291",Group2 b
"B11135072",Group2 b
"B33199603",Group1
"B11137879",Group3
"B11110603",Group2 b
"B11110927",Group3
"B11147712",Group3
"B33191224",Group1
"B11131290",Group3
"B11157974",Group1
"B33191224",Group1
"B11141503",Group2 b
"C11137159",Group1
"B33199522",