I have tab-delimited text file containing about more than 1500 rows.input.txtid   sno1   EN1  Nucus_2158_mri_1/2_Co_1.0_Le_3104EN2  Nucus_2158_mri_4/2_Co_1.0_Le_3104EN3  Nucus_2158_mri_1/2_Co_1.0_Le_3104EN4  Nucus_2158_mri_1/2_Co_1.0_Le_3106EN5  Nucus_2158_mri_1/2_Co_1.0_Le_3104EN6  Nucus_2159_mri_1/2_Co_1.0_Le_3104I want to get exact match within column (sno1) by capturing bracketed values (Nucus_{2158}_mri_{1/2}_Co_1.0_Le_{3104}) and print their matching ids list. Any help in awk/sed appreciated.output.txtNucus_2158_mri_1/2_Co_1.0_Le_3104 EN1,EN3,EN5
Matching values within columns
sed;awk
Assuming you mean the whole second element is the same in each case, you can use it as the key in an associative array. Here is an awk example that relies on that:awk '/^EN/ {  if(H[$2] == )    H[$2] = $1  else    H[$2] = H[$2],$1}END {  for(key in H)    print key, H[key]}' infileOutput:Nucus_2158_mri_4/2_Co_1.0_Le_3104 EN2Nucus_2159_mri_1/2_Co_1.0_Le_3104 EN6Nucus_2158_mri_1/2_Co_1.0_Le_3104 EN1,EN3,EN5Nucus_2158_mri_1/2_Co_1.0_Le_3106 EN4