sed - 仅删除带有元音的单词

发布于 2024-12-20 05:01:38 字数 219 浏览 4 评论 0原文

我正在尝试删除所有以元音开头的单词,如下所示。我的 sed 命令仅删除第一个带有元音的单词,而不删除任何其他单词。我认为下面的边界标记并使用 g 会捕获所有单词,但它没有这样做。我怎样才能得到所有带有元音的单词?

echo "Always take a Big Apple " | sed -r 's/\b^[AEIOUaeiou]\w*//g'

I am trying to delete all words that start with a vowel as per below. The sed command I have is only deleting the first word if it has a vowel, not any others. I thought the boundary marker below and using the g would capture all words but it is not doing it. How do I get it to get all words with vowels ?

echo "Always take a Big Apple " | sed -r 's/\b^[AEIOUaeiou]\w*//g'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

天煞孤星 2024-12-27 05:01:38

删除 ^

sed -r 's/\b[AEIOUaeiou]\w*//g'

您不需要将其锚定到行首,足以满足您要求它位于单词边界上的要求。

Remove ^

sed -r 's/\b[AEIOUaeiou]\w*//g'

you don't need to anchor it to the beginning of line, enough that you request it to be on the word boundary.

¢好甜 2024-12-27 05:01:38
echo "Always take a Big Apple " | sed -r 's/\b[AEIOUaeiou]\w*//g' 
echo "Always take a Big Apple " | sed -r 's/\b[AEIOUaeiou]\w*//g' 
昔日梦未散 2024-12-27 05:01:38

这个 GNU sed 解决方案可能适合您:

echo "Always take a Big Apple " | sed 's/\<[aeiou]\w*//Ig'

This GNU sed solution might work for you:

echo "Always take a Big Apple " | sed 's/\<[aeiou]\w*//Ig'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文