I have a text file which has 4 columns and data looks like:
P_ID C_ID Code MSG 10 12 001 abcd 20 21 003 jklm 10 12 002 hijk Here P_ID, C_ID, Code and MSG are columns.
A search needs to be made against column C_ID , if there are multiple entries for a same C_ID value but have different code and MSG column values then the final file should have results as shown in the expected output file below where code and msg column values are concatenated with comma in a single row.
Expected output should be like :
P_ID C_ID Code MSG 10 12 001,002 abcd,hijk 20 21 003 jklm following is the output:
1: NF=4 $1=[P_ID] $2=[C_ID] $3=[Code] $4=[MSG] 2: NF=4 $1=[10] $2=[12] $3=[001] $4=[abcd] 3: NF=4 $1=[20] $2=[21] $3=[003] $4=[jklm] 4: NF=4 $1=[10] $2=[12] $3=[002] $4=[hijk] The output for the solution provided in first answer was:
P_ID C_ID Code MSG 10 12 001 abcd 20 21 003 jklm 10 12 002 hijk The awk command to check the column name and corresponding data is working fine however the first command provided as an answer is not giving the expected result.