awk - 在 awk 中使用多个分隔符

我有一个文件,其中包含以下几行:

/logs/tc0001/tomcat/tomcat7.1/conf/catalina.properties:app.env.server.name = demo.example.com
/logs/tc0001/tomcat/tomcat7.2/conf/catalina.properties:app.env.server.name = quest.example.com
/logs/tc0001/tomcat/tomcat7.5/conf/catalina.properties:app.env.server.name = www.example.com

在上面的输出中,我想提取 3 个字段(数字 2、4 和最后一个 *.example.com)。我得到以下输出:

cat file | awk -F'/' '{print $3 "\t" $5}'
tc0001   tomcat7.1
tc0001   tomcat7.2
tc0001   tomcat7.5

我如何也提取 '=' 之后的域名的最后一个字段?如何使用多重分隔符提取字段?

最佳答案

分隔符可以是正则表达式。

awk -F'[/=]' '{print $3 "\t" $5 "\t" $8}' file

生产:

tc0001   tomcat7.1    demo.example.com  
tc0001   tomcat7.2    quest.example.com  
tc0001   tomcat7.5    www.example.com

https://stackoverflow.com/questions/12204192/

相关文章:

python - 将带参数的函数传递给Python中的另一个函数?

python - 在 Windows 上设置 Python simpleHTTPserver

python - 在 Python 中将字符串日期转换为时间戳

linux - Windows 容器可以托管在 Linux 上吗?

linux - 在fish shell中定义别名

linux - 如何在 Linux VM 的控制台上向上/向下滚动

linux - 如何对目录中的所有文件执行grep操作?

linux - crontab 星期几语法

python - _csv.Error : field larger than field limi

python - 将 UTC 日期时间字符串转换为本地日期时间