Tylemaster
Tylemaster

Reputation: 37

How to eliminate # of columns in a pipe delimited file, in vim

I have a pipe-delimited file I am working with in Vim, how can I eliminate columns using this? For example - deleting everything before the third pipe on every line of the file

Upvotes: 0

Views: 84

Answers (1)

Sherman Chen
Sherman Chen

Reputation: 329

Method 1

  1. If your pipe delimited lines start at line #1, move the cursor to line #1, and press Shift-o (letter 'o') to add a blank line above your first line.

  2. Make sure the cursor is in the new first line. Press

    q a

    to start to record your key stroke series into register 'a'. (q - start to record; a - record to register 'a')

  3. Press

    j d 3 f | q

    (j - down; d - delete; 3 - the 3rd pipe; f - find; | - pipe sign; q - finish recording)

  4. Press

    u

    to undo the deletion.

  5. Check how many lines are there all together, say, 1000.

  6. Move the cursor back to the first line, then press

    1000 @ a

    (1000 - run the recorded key stroke series 1000 times; @ - run the recorded key stroke series; a - in register 'a')

    You have achieved what you want.

Method 2

:%normal 0d3f|

Please read the help for normal
:h normal

Upvotes: 1

Related Questions