[bash] Best way to simulate "group by" from bash?