grep或sed用于包含字符串的单词 [英] grep or sed for word containing string
本文介绍了grep或sed用于包含字符串的单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
示例文件:
blahblah 123.a.site.com some-junk
yoyoyoyo 456.a.site.com more-junk
hihohiho 123.a.site.org junk-in-the-trunk
lalalala 456.a.site.org monkey-junk
我想在每行中间将所有这些域都grep出来,它们都有一个共同的部分 a.site
,我可以用它来grep,但是我不知道该怎么做不用返回整行就可以了吗?
I want to grep out all those domains in the middle of each line, they all have a common part a.site
with which I can grep for, but I can't work out how to do it without returning the whole line?
在这里可能需要sed或正则表达式,因为简单的grep还不够吗?
Maybe sed or a regex is need here as a simple grep isn't enough?
推荐答案
您可以这样做:
grep -o '[^ ]*a\.site[^ ]*' input
或
awk '{print $2}' input
或
sed -e 's/.*\([^ ]*a\.site[^ ]*\).*/\1/g' input
这篇关于grep或sed用于包含字符串的单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文