我从Nagios使用命令wget
下载了html文件,然后使用以下命令将该html文件转换为文本文件:
html2text -width 180 file.html >1.txt
警报摘要报告
Most Recent Alerts
08-01-2018 06:11:52 to 08-10-2018
Duration: 7d 0h 0m 0s
Report Options Summary:
Alert Types: Host & Service Alerts
State Types: Hard States
Host States: Up, Down, Unreachable
Service States: Warning, Unknown, Critical
Displaying all 4 matching alerts
DISK OK - free space: CRITICAL
01-08-2018 07:05:05 Service Required Critical CPU:loadaverage 6.0%
01-08-2018 07:10:25 Service Alert Critical memoryUsage
DISK OK - free space:
02-08-2018 01:05:2018 Service Alert Warning memoryUsage
CRITICAl:outstanding alert attention
02-08-2018 02:05:2018 Service Alert Critical required
然后,我使用以下命令剪切前十行:
awk 'NR > 10 { print }'1.txt > 2.txt
这是文件2.txt的内容:
DISK OK - free space: CRITICAL
01-08-2018 07:05:05 Service Required Critical CPU:loadaverage 6.0%
01-08-2018 07:10:25 Service Alert Critical memoryUsage
DISK OK - free space:
02-08-2018 01:05:2018 Service Alert Warning memoryUsage
CRITICAl:outstanding alert attention
02-08-2018 02:05:2018 Service Alert Critical required
我不希望将两行合并为一行,而仅将b.txt文件的特定输出合并为一行。
注意:文本文件包含N行数
预期输出:
01-08-2018 07:05:05 DISK OK - free space:Service Required Critical CRITICALservice requiredCPU:loadaverage 6.0%
01-08-2018 07:10:25 Service Alert Critical memoryUsage
02-08-201801:05:2018 DISK OK - free space:Service Alert Warning memoryUsage
02-08-2018 02:05:2018 Service Alert Critical CRITICAL:outstanding alert attention required