fork download
  1. #!/bin/bash
  2.  
  3.  
  4. echo "host1,app1
  5. host1,app2
  6. host1,app3
  7. host2,app4
  8. host2,app5
  9. host2,app6
  10. host3,app1" | awk -F, 'NR == 1 { currentHost=$1; currentApps=$2 }
  11. NR > 1 && currentHost == $1 { currentApps=currentApps "," $2 }
  12. NR > 1 && currentHost != $1 { print currentHost ";" currentApps; currentHost=$1; currentApps=$2 }
  13. END { print currentHost ";" currentApps }'
Success #stdin #stdout 0s 4384KB
stdin
Standard input is empty
stdout
host1;app1,app2,app3
host2;app4,app5,app6
host3;app1