Replacing a template at the end of a file with sed

Using sed, if there is a space character in the file line, I need to print the output with a space character and something after it is deleted. Code example:

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

So, let's say the file says this line by line:

  Chuck Norris is the man 

I just need to print:

  Chuck 

Several lines also apply:

 Chuck Norris is the man So is Arnold 

Replaced by:

 Chuck So 
+4
source share
1 answer

This should do it for you:

 sed 's/ .*//g' file 

To remove from the beginning of a line to the first space, use the following command:

 sed 's/^[^ ]* //g' 
+2
source

All Articles