我使用 wget 命令从 Nagios 下载了它的 html 文件,然后使用以下代码将该 html 文件转换为 Textfile:
html2text -width 180 file.html >a.txt
然后我剪切了前 10 行,因为我不需要该文本,并且得到了以下文本文件输出
awk 'NR > 10 { print }'a.txt > b.txt
我必须将两行合并为单行,不适用于所有行,仅适用于 b.txt 文件的特定输出。
注意:文本文件包含N行
这里是 b.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
预期输出:
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
提前致谢
您可以使用 awk 将行合并在一起:
awk '
/^ +/{ # For lines starting with spaces,
gsub(/^ +/," "); # Replace these multiple spaces with only one
a=a $0; # Store the line into the variable a
next # Continue with the next line
}
{ # For lines not starting with spaces
$3=$3 a; # Append the variable a to the third element
a="" # Clear variable a
}
1 # Print the current line
' b.txt
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)