linux - 连接字符串之间的行 - bash

标签 linux bash join merge

我有一个 nmap 输出文件,其中包含类似于 -

Nmap scan report for myserver1 (11.11.11.11)

OS CPE: cpe:/o:microsoft:windows_server_2003::sp2

OS details: Microsoft Windows Server 2003 SP2

Nmap scan report for myserver2 (22.22.22.22)

OS CPE: cpe:/o:microsoft:windows_server_2003::sp2

OS details: Microsoft Windows Server 2003 SP2

Nmap scan report for 33.33.33.33

OS CPE: cpe:/o:microsoft:windows_xp::sp3

Aggressive OS guesses: Microsoft Windows XP SP3 (98%), Microsoft Windows Server 2003 SP2 (96%), Microsoft Windows XP (94%), Microsoft Windows Server 2003 SP0 or Windows XP SP2 (94%), Microsoft Windows XP SP2 (94%), Microsoft Windows XP SP2 - SP3 (94%), Microsoft Windows Server 2003 SP1 or SP2 (92%), Microsoft Windows XP SP2 or SP3 (91%), Microsoft Windows Server 2003 (91%), Belkin OmniView KVM switch or SMA Sunny WebBox solar panel monitor (90%)

No exact OS matches for host (test conditions non-ideal).

....etc

我想将每个服务器特定的所有行合并为一行,从“Nmap 扫描报告”开始。每个服务器的行数可以是可变的,所以我不能使用 grep -A。有人有什么建议吗?

最佳答案

我的建议:

tr "\n" " " < filename | sed -r "s/ (Nmap scan report for)/\n\1/g"

关于linux - 连接字符串之间的行 - bash,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24790076/

相关文章:

c - 为什么 perf 显示的浮点事件少于预期?

linux - 如何使用公钥加密openssl中的大文件

python - 跨平台部署Python Qt应用 : Win, OSX, Linux

bash - 比赛后追加sed?

linux输出通过主机名grep一个内部ip

linux - BASH 脚本 : take a filename (with spaces) as argument and use name (no ext) and also full filename as args for scripted command

bash - 基于目录的环境变量范围——如何实现?

MySQL LEFT JOIN and ON w/LIKE - 这个查询不会运行但是匹配确实存在

mysql - SQL - 连接表但并不总是

mysql - 使用什么类型的连接?