linux - 如何使用 sed、awk 只打印特定单词的路径?

标签 linux bash awk sed

我有一个如下所示的文本文件:

ErrorLog "|/usr/local/apache2/bin/rotatelogs /var/log/apache/error_log.%Y-%m 200M"

ErrorLog "/var/log/apache2/error_log"

我只需要过滤带有单词error_log的路径。 我需要输出为:

/var/log/apache2/error_log.%Y-%m

或者

/var/log/apache2/error_log

最佳答案

grep :

grep -o '[^[:space:]]*\<error_log\>[^[:space:]]*' file
  • [^[:space:]]* - 匹配非空白字符
  • \<\> - 是单词边界
<小时/>

示例输出:

/var/log/apache/error_log.%Y-%m
"/var/log/apache2/error_log"

关于linux - 如何使用 sed、awk 只打印特定单词的路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47678879/

相关文章:

linux - UNIX基本getopts麻烦

Linux:每行的最大值之和

bash - 崩溃时自动重启 SH 脚本?

bash - 在一个文件中查找不在另一个文件中的行的快速方法?

regex - 如何在 linux shell 中使用 sed 选择内容

java - MongoDB Java 驱动错误

linux - IO 阻塞进程是否会在 'top' 输出中显示 100% 的 CPU 使用率?

linux - 用于复制目录中的所有文件并附加 filenameCopy 的 Bash 脚本

regex - 使用 Bash 将字符串添加到正则表达式匹配前面

variables - AWK 通过传递变量在特定行替换模式