SED bash 脚本帮助
我正在尝试跟踪我的朋友正在关注的人(全部 1,522 个)
,并从他的 Twitter 页面获取了一个文本文件,我只想查看以 @
。
示例:(
Podcaster, broadcaster and tech pundit. The Tech Guy on the Premiere Radio
Networks. Live at live.twit.tv For my link feed follow @links_for_twit
换行以删除可恶的水平滚动条。)
我希望将其变成 @links_for_twit
。
I'm trying to follow who my friend is following (all 1,522 of them)
and a got a text file with from his twitter page and I want to see just the last word of a line that begins with @
.
Example:
Podcaster, broadcaster and tech pundit. The Tech Guy on the Premiere Radio
Networks. Live at live.twit.tv For my link feed follow @links_for_twit
(Line-wrapped to remove hateful horizontal scrollbar.)
I want that to turn into @links_for_twit
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用 awk 代替:
Use awk instead:
你的意思是,比如:
?
You mean, like:
?
如果您想使用 sed,请尝试以下操作:
sed -n 's/.*\(@.*\)/\1/p'
-n
:除非要求,否则不打印任何内容s/.*\(@.*\)
:捕获行/\1/
中最后一个“@”之后的所有内容:替换 的整行带有捕获位
p
:如果进行了替换,则打印希望有帮助
编辑:我刚刚看到下面有关电子邮件地址的投诉。您可以在 @ 之前添加
\s
以确保有空格:sed -n 's/.*\s(@.*\)/\1/p'
If you're wanting to use sed, try this:
sed -n 's/.*\(@.*\)/\1/p'
-n
: don't print anything unless askeds/.*\(@.*\)
: capture everything after the last '@' in the line/\1/
: replace the whole line with the captured bitp
: print if a substitution was madeHope that helps
EDIT: I just saw the complaint below about email addresses. you can add
\s
just before the @ to ensure there's a space:sed -n 's/.*\s(@.*\)/\1/p'
如果您有 GNU grep,则可以使用 Perl 风格的正则表达式来确保
@
位于单词的开头:If you have GNU grep, you could use a Perl-flavoured regex to ensure the
@
is at the start of a word: