【问题标题】:Replacing a pattern to the end of a file with sed用 sed 将模式替换到文件末尾
【发布时间】:2012-07-01 00:37:06
【问题描述】:

使用 sed,如果文件中的一行上有空格字符,我需要打印带有空格字符的输出以及删除后的任何内容。代码示例:

sed "s/"something here I think"//g' file

所以,假设一个文件在一行上说:

 Chuck Norris is the man

我只需要它打印:

 Chuck

多行也适用:

Chuck Norris is the man
So is Arnold

替换:

Chuck
So

【问题讨论】:

    标签: linux unix sed


    【解决方案1】:

    这应该为你做:

    sed 's/ .*//g'  file
    

    要从行首删除到第一个空格,请使用:

    sed 's/^[^ ]* //g'
    

    【讨论】:

    • 但是如果我需要删除第一个空格和它之前的任何内容怎么办?我做了 sed 's/.* //' 文件,但没有正常工作。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-10
    • 2012-07-25
    • 2018-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多