包含字符串的单词的 grep 或 sed [英] grep or sed for word containing string

查看:19
本文介绍了包含字符串的单词的 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

我想在每一行的中间找出所有这些域,它们都有一个共同的部分 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屋!

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