解析使用awk日志文件 [英] parsing a log file with awk
问题描述
我尝试解析日志文件具有以下code:
I am try to parse a log file with the following code:
if [[ $line -match "=====.*" ]]; then
awk $2 = $vFiler;
echo "$vFiler";
说明:
有开始像 =====
或体积/ ...后面加上一个名称的图案线条
我想找出谁与启动=====
or'vol / ...,并设置如下等于一个变量的字符串,但我真的很努力在做的所有行它,我想过使用awk(我知道-match没有真正的命令)。
there are lines starting with a pattern like =====
or 'vol/...' followed by a name
I want find all lines who start with =====
or'vol/...' and set the string that follows equals a variable, but I am really struggling doing it, i thought about a if command with awk (I know that -match is no real command).
输入如下:
===== vfiler0
/vol/vol0
===== vFiler1
/vol/vol1
输出应该是:
vFiler, Type
vFiler0, /vol/vol0
vFiler1, /vol/vol1
你们可以帮助我吗?我试图做一个bash脚本
是有可能得到这是一个如果......就像我上面试过吗?
can you guys help me? I am trying to do this in a bash script is it possible to get it a "if ..." like i tried above?
推荐答案
我会用以下内容:
awk -v RS="=====" -v OFS="," 'BEGIN {print "vFiler", "Type" } NF{print $1, $2}' file
返回的是:
vFiler,Type
vfiler0,/vol/vol0
vFiler1,/vol/vol1
我们做的是设置记录分隔符为 =====
。这样一来,块====
将每一次处理。然后,我们打印的第一和第二场,每当有至少有一个( NF
)。
What we do is to set the record separator as =====
. This way, a block of ====
will be handled every time. Then, we print the first and second field whenever there is at least one (NF
).
这篇关于解析使用awk日志文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!