GREP由awk产生 [英] GREP by result of awk

查看:61
本文介绍了GREP由awk产生的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

awk'{print $ 4}'的输出是

Output of awk '{print $4}' is

b05808aa-c6ad-4d30-a334-198ff5726f7c
59996d37-9008-4b3b-ab22-340955cb6019
2b41f358-ff6d-418c-a0d3-ac7151c03b78
7ac4995c-ff2c-4717-a2ac-e6870a5670f0

我需要通过这些记录来grep文件st.log.像 awk'{print $ 4}'之类的| xargs -i grep -w"awk的模式" st.log 我不知道如何正确传递模式吗?

I need to grep file st.log by these records. Something like awk '{print $4}' |xargs -i grep -w "pattern from awk" st.log I dont know how to pass pattern correctly?

推荐答案

awk '{print $4}' | grep -F -f - st.log

Eric Renouf的信用,他注意到 -f-可以用于标准输入,而不是 -f<(cat),请注意: -f/dev/stdin 也可以,并且避免启动新进程.

Credits to Eric Renouf, who noticed that -f - can be used for standard input instead -f <(cat), Note: -f /dev/stdin also works and avoids launching a new process.

或更接近问题以对输出进行排序

or closer to the question to have the output ordered

awk '{print $4}' | xargs -i grep -F {} st.log 

也许 -w 不是OP所需的选项,而是 -F

maybe -w was not the option OP needed but -F

grep --help
-F, --fixed-strings       PATTERN is a set of newline-separated strings
-w, --word-regexp         force PATTERN to match only whole words

-w 仅匹配完全包含模式的行

-w will match only line that contain exactly pattern

示例

grep -w . <<<a       # matches
grep -w . <<<ab      # doesn't match
grep -F . <<<a       # doesn't match
grep -F . <<<a.b     # matches

这篇关于GREP由awk产生的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆