I have a text file and I want to remove every word except the first word on every line and I have no idea how to do this.
So, if I have:
one two three
four five
six
I want to remain with:
one
four
six
Got any ideas?
Start visual-block by Ctrl+v . Select second column (e.g. by pressing: W , G ). Delete it by pressing d .
To delete all line you can use either the % symbol that represents all lines or the 1,$ range: Press the Esc key to go to normal mode. Type %d and hit Enter to delete all the lines.
Immediately after opening a file, type “gg” to move the cursor to the first line of the file, assuming it is not already there. Then type dG to delete all the lines or text in it.
If the lines don't start with whitespace, you could replace ' .*'
(which matches everything after the first word) with an empty string:
:%s/ .*//g
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With