I am trying to go through a file, and delete the last word in each line. Currently, I am using the command
sed 's/^*\n//' old.txt > new.txt
but it is coming out that old.txt is the same as new.txt. Thanks for any help, and let me know if I can clarify the question. Also, in order to define ‘word’ I am just using spaces.
Try the following.
\w*matches the last word inside of the file and$anchors the search to the end of the line.The reason that old.txt is coming out as new.txt is likely because your regular expression
^*\nis not matching any lines in old.txt.