Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 用sed替换文件末尾的模式_Linux_Unix_Sed - Fatal编程技术网

Linux 用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,如果文件中的一行上有空格字符,我需要打印带有空格字符的输出以及删除后的任何内容。代码示例:

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的/*/'文件,但没有正常工作。