다음과 같은 Nmap 출력 파일이 있습니다.
Nmap scan report for AAAAAAAAAAAAAAAAAA.akamaitechnologies.com (IP)
Host is up, received user-set (0.027s latency).
Scanned at 2016-10-09 14:43:24 CEST for 15s
PORT STATE SERVICE REASON VERSION
443/tcp open ssl/http syn-ack ttl 59 AkamaiGHost (Akamai's HTTP Acceleration/Mirror service)
Nmap scan report for AAAAAAAAAAAAAAAAAA.akamaitechnologies.com (IP)
Host is up, received user-set.
Scanned at 2016-10-09 14:43:21 CEST for 2s
PORT STATE SERVICE REASON VERSION
2222/tcp filtered EtherNetIP-1 no-response
Nmap scan report for CCCCCCCCCCC. googleusercontent.com (IP)
Host is up, received user-set (0.15s latency).
Scanned at 2016-10-09 14:43:21 CEST for 3s
PORT STATE SERVICE REASON VERSION
2222/tcp open ssh syn-ack ttl 55 ProFTPD mod_sftp 0.9.9 (protocol 2.0)
Nmap scan report for BBBBBBBBBBBBBBBBBBB
Host is up, received user-set (0.16s latency).
Scanned at 2016-10-09 14:43:21 CEST for 3s
PORT STATE SERVICE REASON VERSION
2222/tcp open ssh syn-ack ttl 51 ProFTPD mod_sftp 0.9.9 (protocol 2.0)
Nmap scan report for AAAAAAAAAAAAAAAAAA.akamaitechnologies.com (IP)
Host is up, received user-set (0.027s latency).
Scanned at 2016-10-09 14:43:24 CEST for 15s
PORT STATE SERVICE REASON VERSION
443/tcp open ssl/http syn-ack ttl 59 AkamaiGHost (Akamai's HTTP Acceleration/Mirror service)
5개 라인 블록마다 정렬 일치 "Nmap Scan Report"를 사용하여 이 파일을 정렬하고 싶습니다. 출력은 다음과 같아야 합니다.
Nmap scan report for AAAAAAAAAAAAAAAAAA.akamaitechnologies.com (IP)
Host is up, received user-set (0.027s latency).
Scanned at 2016-10-09 14:43:24 CEST for 15s
PORT STATE SERVICE REASON VERSION
443/tcp open ssl/http syn-ack ttl 59 AkamaiGHost (Akamai's HTTP Acceleration/Mirror service)
Nmap scan report for AAAAAAAAAAAAAAAAAA.akamaitechnologies.com (IP)
Host is up, received user-set.
Scanned at 2016-10-09 14:43:21 CEST for 2s
PORT STATE SERVICE REASON VERSION
2222/tcp filtered EtherNetIP-1 no-response
Nmap scan report for BBBBBBBBBBBBBBBBBBB
Host is up, received user-set (0.16s latency).
Scanned at 2016-10-09 14:43:21 CEST for 3s
PORT STATE SERVICE REASON VERSION
2222/tcp open ssh syn-ack ttl 51 ProFTPD mod_sftp 0.9.9 (protocol 2.0)
Nmap scan report for CCCCCCCCCCC. googleusercontent.com (IP)
Host is up, received user-set (0.15s latency).
Scanned at 2016-10-09 14:43:21 CEST for 3s
PORT STATE SERVICE REASON VERSION
2222/tcp open ssh syn-ack ttl 55 ProFTPD mod_sftp 0.9.9 (protocol 2.0)
유닉스 명령을 사용하는 솔루션을 높이 평가합니다.
답변1
5줄 블록의 연결된 각 줄에 대해(예: \x02
입력에서 그럴 가능성이 낮은 낮은 ASCII 문자 사용 - 도구가 지원한다고 가정) 첫 번째 필드를 정렬한 다음 개행을 복원합니다.
sed 'N;N;N;N;s/\n/\x02/g' infile | sort -t$'\02' -k1,1 | tr '\02' '\n'