Is it possible to transform this:
1 Alice
1 Bob
1 Cary
2 Dan
3 Eve
3 Fred
into this:
1 Alice,Bob,Cary
2 Dan
3 Eve,Fred
using shell? (without Perl, Ruby, Python etc)
feedback
|
|
| |||||||||||
feedback
|
|
Using associative arrays in bash version 4:
| |||
|
feedback
|
|
Crap I couldn't resist the challenge. Here's my solution in shell (bash to be exact) as a oneliner:
which produces the desired output, properly formatted:
Assumptions:
If #2 is not valid, you need to run the input through If I find out I just answered your homework I will be extremely annoyed. My only consolation is that if your teacher sees what I wrote they will think you are nuts. | |||||
feedback
|
|
This one over at stackoverflow is very similar and has some good answers: http://stackoverflow.com/questions/380817/best-way-to-simulate-group-by-from-bash | |||
|
feedback
|