소스 검색

Add combine-by-prefix

master
JustAnotherArchivist 2 년 전
부모
커밋
a3a2979508
1개의 변경된 파일6개의 추가작업 그리고 0개의 파일을 삭제
  1. +6
    -0
      combine-by-prefix

+ 6
- 0
combine-by-prefix 파일 보기

@@ -0,0 +1,6 @@
#!/bin/bash
# Usage: pass lines into stdin; consecutive lines with the same first field (everything up to the first whitespace) will be grouped together on stdout.
# Input lines: 'A 1', 'A 2', 'B 3', 'C 4', 'C 5', 'B 6'
# Output lines: 'A 1 2', 'B 3', 'C 4 5', 'B 6'
# Whitespace within input lines beyond the first whitespace after the prefix is preserved. A single space is used to separate prefix and combined lines.
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"; }'

불러오는 중...
취소
저장