shell - Group by the file by 1st coulmn -
shell - Group by the file by 1st coulmn -
i have comma seperated 3 filed file, need grouping file based on 1st coulmn. based on 1st filed, if there more 1 rows having same 1st column value need grouping 2nd , 3rd column values based on 1st column
sample input
aplple,shop1,11 aplple,shop2,11 orange,shop7,22 pine,shop8,23 pine,shop9,23 pine,shop11,23 pine,shop15,23 expected output
aplple 11 shop1 shop2 orange 22 shop7 pine 23 shop9 shop11 shop15
here 1 awk solution:
awk -f, '{print ($1!=prev?$1rs$3rs$2:$2);prev=$1}' file aplple 11 shop1 shop2 orange 22 shop7 pine 23 shop8 shop9 shop11 shop15 shell unix awk
Comments
Post a Comment