我想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)
请更正此命令或提供正确的命令。