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.

closed as off-topic by Zanna, αғsнιη, karel, user364819, Pilot6 Jul 17 '17 at 11:43

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This is not about Ubuntu. Questions about other Linux distributions can be asked on Unix & Linux, those about Windows on Super User, those about Apple products on Ask Different and generic programming questions on Stack Overflow." – Zanna, αғsнιη, karel, Community, Pilot6
If this question can be reworded to fit the rules in the help center, please edit the question.

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 9: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

Not the answer you're looking for? Browse other questions tagged or ask your own question.