How can I delete the 5th word of every line in a file?

How about cut :

$ cut -d' ' -f1-4,6- file.txt 
File is not updated and will be removed  
System will shut down within 10 seconds  
Please save your work or copy to other location  
Kindly cooperate with us
  • -d' ' sets the delimiter as space

  • -f1-4,6- selects the first to 4th field (word), leaving the 5th one and then continue printing from 6th to the rest.


A solution with cut:

cut -d ' ' -f1-4 -f6- FILE

awk: remove the 5th field

awk '{for (i=5; i<NF; i++) $i = $(i+1); NF--};1' file

If you want to save the file in-place: https://stackoverflow.com/q/16529716/7552

You could just erase the contents of the 5th field, but that leaves 2 consecutive output field separators:

awk '{$5 = ""};1' file