Answer» Hi,
I have been thinking of how to script this but i have no clue at all.. Could someone please HELP me out or give me some idea on this?
I WOULD like to GROUP those lines with the same first variable in each line, joining the 2nd variables with commas. Let's say i have the following input.
Code: [Select]aa c1 aa c2 aa c3 cc d1 dd e1 dd e2 ee f1
I would like the output to be like this.
Code: [Select]aa c1,c2,c3 cc d1 dd e1,e2 ee f1
Could this be easily done with bash script? Or should i TRY perl script then? I'm a beginner in bash script and perl.
Thank you. I've found a way to solve this. ${input} is the filename for the input file.
Code: [Select]for m in `CAT ${input} | awk '{print $1}' | sort | uniq ` do var=`grep "^${m} " ${output} | awk '{print $2}' | tr '\n' ',' | sed '$s/,$//'` echo "${m} ${var}" done
|