小编ama*_*108的帖子

grep grep命令的输出字符串

我想grep根据错误“MyOwnError”从日志中获取 Id,然后使用相同的 Id 来获取整个日志中出现 Id 的整行。

例如:

假设有一个文件File1

animal:Dogs hate the animal:catsF and no-one else
animal:catsF hate the animal:fish
animal:catsF also hate animal:humans
Run Code Online (Sandbox Code Playgroud)

我的搜索字符串是“Dogs”

grep 'Dogs' File1 | grep -o 'animal:.*F'
Run Code Online (Sandbox Code Playgroud)

这会给我animal:catsF,现在我想要grep同一文件的“catsF” File1

我尝试过xargs,但它选择了文件名而不是参数。

grep 'Dogs' File1 | grep -o 'animal:.*F' | xargs grep File1
Run Code Online (Sandbox Code Playgroud)

请更正此命令或提供正确的命令。

linux bash

2
推荐指数
1
解决办法
1896
查看次数

标签 统计

bash ×1

linux ×1