How to use cut command inside vim [closed]

I know this should be very simple but due to some reason I am not able to get this working.

say I have a simple file with multiple columns of data, I just want to get second column and remove other columns, while I have that file opened in vim. As answered here, I use following in vim:

:%!cut -f2

But it just shows following, but contents of file is still same.

6 lines filtered

See the screenshots attached:

enter image description here

enter image description here

I want to change the contents of file and have only second column there. I am using Mac.

1

1 Answer

The cut command assumes a tab delimited file. So you should first replace the spaces with a tab. The following will do this for you:

:%s/\s\+/\t/g

followed by the cut command that you already figured out :)

:%!cut -f2
2

You Might Also Like