[英]how to combine multiple awk commands using different options
I need some help in joining the below 3 awk commands using different options.在使用不同选项加入以下 3 个 awk 命令时,我需要一些帮助。
Input Text file format : /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输入文本文件格式:/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
I need to extract the 6th, 8th, 13th (date-timestamp), 13th (1.2.3 version) and print them into a csv file with headers.我需要提取第 6、8、13(日期时间戳)、第 13(1.2.3 版本)并将它们打印到带有标题的 csv 文件中。 Sample Output :
样本输出:
SPK ![]() |
REPO![]() |
log4j-version ![]() |
Timestamp![]() |
---|---|---|---|
TAIS![]() |
tais_aem_build ![]() |
1.2.3 ![]() |
2022-06-23T07:23:56.117Z ![]() |
Using multiple delimiters使用多个分隔符
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
Or changing all delimiters to /
或将所有分隔符更改为
/
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
Or using 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.