1

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.

Saurabh
  • 185

1 Answers1

2

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
  • Pardon my ignorance, what does it mean by 6 lines filtered? – Saurabh Jul 16 '17 at 09:05
  • Because the cut command filtered (in this case the 2nd column out of) the (in this case 6) lines. So it basically tells you what it did :). It's not an error message. – Kees Beets Jul 16 '17 at 10:01