linux - 如何grep具有变量的确切字符串

标签 linux bash unix grep

我有一个如下所示的文件,我只想搜索 "this[*]: world * seconds" 其中 * 表示变量

sudo cat log | grep "world" | grep this -m1
Apr 26 04:19:12 : SESSION = 111, from_remote_host = , USER = root, PWD = /root, CMD = 2018-04-26 04:19:12 sudo cat log | grep "world" | grep this -m10
Apr 26 04:18:45 xxxx aaaaaaaaaaaaaaaaaa: SESSION = 101675, from_remote_host = jjjjjjj, USER = root, PWD = /root, CMD = 2018-04-26 04:18:45 sudo cat log | grep "world" | grep this -m1
Apr 26 04:11:54 xxxx this[98461]: world 29.93 seconds
Apr 26 03:41:50 xxxx this[77844]: world 18.87 seconds
Apr 26 03:11:36 xxxx this[58682]: world 18.60 seconds
Apr 26 02:42:29 xxxx this[43432]: world 34.56 seconds

最佳答案

我认为这条线会做你想做的事:

grep -E 'this\[[0-9]+\]: world [0-9.]+ seconds' file

关于linux - 如何grep具有变量的确切字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50041330/

相关文章:

linux - 如何根据最后一个单词PATH中的前两个字符对文件进行排序

bash - 通过 bash 调用应用程序时忽略 dyld_insert_libraries

bash - 如何使用 awk 基于公共(public)字段合并文件中的行?

linux - 运行进程nohup

通过 SNMP 监控 Java 应用程序

c++ - 使用 execv 从 C++ 启动服务

linux - 任何人都可以解释一下这个命令是如何工作的吗?

linux - Syscfg 错误 KNL - 错误 : Failed in export HII base address from SMI driver

bash/shell 多次读取 LINE

shell - 测试 unix 中是否存在可执行文件