Linux 用sed替换文件末尾的模式
使用sed,如果文件中的一行上有空格字符,我需要打印带有空格字符的输出以及删除后的任何内容。代码示例:Linux 用sed替换文件末尾的模式,linux,unix,sed,Linux,Unix,Sed,使用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 这应该可以为您做到: sed 's/ .*//g' file 要
sed "s/"something here I think"//g' file
那么,假设一个文件在一行上写着:
Chuck Norris is the man
我只需要把它打印出来:
Chuck
多行也适用:
Chuck Norris is the man
So is Arnold
取代:
Chuck
So
这应该可以为您做到:
sed 's/ .*//g' file
要从行首删除到第一个空格,请使用以下命令:
sed 's/^[^ ]* //g'
但是如果我需要移除第一个空间,以及它之前的任何东西呢?我做了sed的/*/'文件,但没有正常工作。