删除文本流中的第一个单词
如何从流中的每行文本中删除第一个单词?
例如,
$ cat myfile
some text 1
some text 2
some text 3
我想:
$ cat myfile | magiccommand
text 1
text 2
text 3
我将如何使用 Bash 来解决这个问题?我可以使用 awk '{print $2 $3 $4 $5 ....}',但这很混乱,并且会导致所有空参数都有额外的空格。我想 sed 也许能够做到这一点,但我找不到任何这样的例子。
How would I remove the first word from each line of text in a stream?
For example,
$ cat myfile
some text 1
some text 2
some text 3
I want:
$ cat myfile | magiccommand
text 1
text 2
text 3
How would I go about this using Bash? I could use awk '{print $2 $3 $4 $5 ....}'
, but that's messy and would result in extra spaces for all null arguments. I was thinking that sed might be able to do this, but I could not find any examples of this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
根据您的示例文本,
应该可以完成这项工作。
Based on your example text,
should do the job.
那应该有效:
That should work:
这是使用 awk 的解决方案
Here is a solution using
awk
运行这个:
您甚至不需要使用管道。
Run this:
You even don't need to use a pipe.
要删除第一个单词,直到出现空格(无论存在多少个空格),请使用:
sed 's/[^ ]* *//'
示例:
To remove the first word, until space no matter how many spaces exist, use:
sed 's/[^ ]* *//'
Example: