Vit*_*liy 3 shell awk grep sed
我有包含一些数据的文件,就像这样
2011-01-02 100100 1
2011-01-02 100200 0
2011-01-02 100199 3
2011-01-02 100235 4
Run Code Online (Sandbox Code Playgroud)
并在单独的文件中有一些"字典"
100100 Event1
100200 Event2
100199 Event3
100235 Event4
Run Code Online (Sandbox Code Playgroud)
而且我知道
0 - warning
1 - error
2 - critical
etc...
Run Code Online (Sandbox Code Playgroud)
我需要SED/AWK/grep的或别的一些脚本,这有助于我收到这样的数据
100100 Event1 Error
100200 Event2 Warning
100199 Event3 Critical
etc
Run Code Online (Sandbox Code Playgroud)
我将非常感谢如何以最佳方式或工作实例来做到这一点
更新
有时我有这样的数据
2011-01-02 100100 1
2011-01-02 sometext 100200 0
2011-01-02 100199 3
2011-01-02 sometext 100235 4
Run Code Online (Sandbox Code Playgroud)
其中sometext =任何6个字符(也许这是有用的信息),
在这种情况下,我需要整个数据:
2011-01-02 sometext EventNameFromDictionary Error
Run Code Online (Sandbox Code Playgroud)
或没有"sometext"
awk 'BEGIN {
lvl[0] = "warning"
lvl[1] = "error"
lvl[2] = "critical"
}
NR == FNR {
evt[$1] = $2; next
}
{
print $2, evt[$2], lvl[$3]
}' dictionary infile
Run Code Online (Sandbox Code Playgroud)