tags:

views:

73

answers:

4

I've got a file with 1000's of entries and 131 columns, the columns are pipe delimited. There is no pipe at the end so format is something like.

2010-10-04|Security|AMEND|20162214| ... lots more columns ... |Bloomberg

How can I remove the last column of the file say in Vim ?

+1  A: 

This regular expression will catch the last column: \|[^|]+$

Abhi
I'm getting pattern not found when I try that one.
Ian Purton
Make sure you've escaped it appropriately for your language
dty
You need `|` not `\|` in vim
justintime
A: 

I would just use cut, or awk at a push

dty
+6  A: 

Tou need

%s/|[^|]*$// 

Note I am using [^|]* to allow for an empty column.

justintime
That's spot on, thanks.
Ian Purton
A: 

Another way:

:%s/.*\zs|.*//
Benoit