fork(4) download
  1. #!/bin/bash
  2.  
  3. awk '{if (/^[^[:blank:]]/) {k=$1; keys[++i]=k} else arr[k] = arr[k] $0 RS}
  4. END{n=asort(keys); for (i=1; i<=n; i++) printf "%s\n%s", keys[i], arr[keys[i]]}'
Success #stdin #stdout 0s 4332KB
stdin
sharpest
  tool
  in
the
  shed
im
  not
  the
stdout
im
  not
  the
sharpest
  tool
  in
the
  shed