The little things give you away... A collection of various small helper stuff
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

7 lines
603 B

  1. #!/bin/bash
  2. # Usage: pass lines into stdin; consecutive lines with the same first field (everything up to the first whitespace) will be grouped together on stdout.
  3. # Input lines: 'A 1', 'A 2', 'B 3', 'C 4', 'C 5', 'B 6'
  4. # Output lines: 'A 1 2', 'B 3', 'C 4 5', 'B 6'
  5. # Whitespace within input lines beyond the first whitespace after the prefix is preserved. A single space is used to separate prefix and combined lines.
  6. exec awk '($1 != lastPrefix) || (NR == 1) { if (NR != 1) { printf "\n"; } printf "%s", $1; lastPrefix = $1; } { printf " %s", substr($0, index($0, FS) + 1); } END { printf "\n"; }'