SED bash 脚本帮助

发布于 2025-01-04 13:24:16 字数 392 浏览 3 评论 0原文

我正在尝试跟踪我的朋友正在关注的人(全部 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

北方的巷 2025-01-11 13:24:16

使用 awk 代替:

 awk '$NF ~ /^@/ {print $NF}'

Use awk instead:

 awk '$NF ~ /^@/ {print $NF}'
夜光 2025-01-11 13:24:16

你的意思是,比如:

grep -o '@[a-zA-Z_0-9]*

tweets.txt

You mean, like:

grep -o '@[a-zA-Z_0-9]*

?

tweets.txt

?

难忘№最初的完美 2025-01-11 13:24:16

如果您想使用 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 asked

s/.*\(@.*\): capture everything after the last '@' in the line

/\1/: replace the whole line with the captured bit

p: print if a substitution was made

Hope 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'

逆光下的微笑 2025-01-11 13:24:16

如果您有 GNU grep,则可以使用 Perl 风格的正则表达式来确保 @ 位于单词的开头:

grep -Po '(?<=^|\s)@\w+' filename

If you have GNU grep, you could use a Perl-flavoured regex to ensure the @ is at the start of a word:

grep -Po '(?<=^|\s)@\w+' filename
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文