我有一个 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/