我需要一些帮助来使用不同的选项连接下面的3个awk命令。
- awk -F/'BEGIN {print "SPK报表"} {print $7,",$9}' -提取第6和第8个字段
- awk -v RS=' '' BEGIN {print "log4j-version"} '/^1/"} -提取第13个字段的版本。
- awk - f '[][]' 'BEGIN {print "Timestamp"} {print $2}' -从第13个字段提取日期时间戳。
输入文本文件格式:/hosting/cbj/shared/master/jobs/TAIS/jobs/tais_aem_build/branches/feature-Dev/builds/214/log:[2022-06-23T07:23:56.117Z] ch.qos.logback.classic。Log4j 0 1.2.3 com.baml.tais.tais_aem_build:jar:6.4.0
我需要提取6日,8日,13日(日期时间戳),13日(1.2.3版本),并将它们打印成一个带有标题的csv文件。输出示例:
<表类>
SPK
回购
log4j-version
时间戳
tbody><<tr>麻将 tais_aem_build 到1.2.3 2022 - 06 - 23 t07:23:56.117z 表类>
使用多个分隔符
awk -F'/|\[|] ?| ' '
BEGIN{
OFS=";"
print "SPK","REPO","log4j-version","Timestamp"
}
{
print $7,$9,$18,$15
}
' file
SPK;REPO;log4j-version;Timestamp
TAIS;tais_aem_build;1.2.3;2022-06-23T07:23:56.117Z
或者将所有分隔符更改为/
awk -F/ '
BEGIN{
OFS=";"
print "SPK","REPO","log4j-version","Timestamp"
}
{
gsub(/[][ ]/, "/");
gsub("//", "/");
print $7,$9,$18,$15
}
' file
SPK;REPO;log4j-version;Timestamp
TAIS;tais_aem_build;1.2.3;2022-06-23T07:23:56.117Z
或者使用split
awk '
BEGIN{
OFS=";"
print "SPK","REPO","log4j-version","Timestamp"
}
{
n=split($1,a,"/")
print a[7],a[9], $4, gensub(/.*[(.*)].*/,"\1",1,a[n])
}
' file
SPK;REPO;log4j-version;Timestamp
TAIS;tais_aem_build;1.2.3;2022-06-23T07:23:56.117Z