[root@station1 ~]# cat data
#[ERROR] [fxmon] [path] attr {vscsi_err_recov} should be , current is
#[ERROR] [fxmon] [path] attr {vscsi_err_recov} should be [fast_fail], current is
#[ERROR] [fxmon] [path] [backing-device] <${_bd}> is an unknow type disk, please check"
#[ERROR] [dwn2] [path] attr {vscsi_err_recov} should be , current is
#[ERROR] [dwn2] [path] attr {vscsi_path_to} should be <30>, current is <0>
#[ERROR] [dwn2] [disk] attr {hcheck_interval} should be <60>, current is <0>
这是文本处理结果:
fxmon|error|path|vscsi0| attr {vscsi_err_recov} should be , current is
fxmon|error|path|vscsi0| attr {vscsi_err_recov} should be [fast_fail], current is
fxmon|error|path|vscsi0| [backing-device] <${_bd}> is an unknow type disk, please check"
这个问题是用sed比是用awk要简单的多,因为其中很多的[],而且不止前三个字段中包含[],后面的数据也有。所以想到是用sed去处理,代码如下:
sed -e 's/^#\[\([^[]*\)\] \[\([^[]*\)\] \[\([^[]*\)\] <\(.\{,10\}\)>/\2|\L\1\E|\3|\4|/' data
perl的代码如下
[root@station1 ~]# cat data | perl -ne 's/^#\[(.*)\] \[(.*)\] \[(.*)\] <(.*?[0-9])>/\2|\L\1\E|\3|\4|/;print '
fxmon|error|path|vscsi0| attr {vscsi_err_recov} should be , current is
fxmon|error|path|vscsi0| attr {vscsi_err_recov} should be [fast_fail], current is
fxmon|error|path|vscsi0| [backing-device] <${_bd}> is an unknow type disk, please check"
dwn2|error|path|vscsi1| attr {vscsi_err_recov} should be , current is
dwn2|error|path|vscsi1| attr {vscsi_path_to} should be <30>, current is <0>
dwn2|error|disk|hdisk0| attr {hcheck_interval} should be <60>, current is <0>
阅读(1522) | 评论(0) | 转发(0) |