Regular expression to remove the last column from a pipe delimited file
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 i开发者_如何学Pythons 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 ?
Tou need
%s/|[^|]*$//
Note I am using [^|]*
to allow for an empty column.
This regular expression will catch the last column: \|[^|]+$
Another way:
:%s/.*\zs|.*//
I would just use cut
, or awk
at a push
精彩评论