title

fire chief's random developer tidbits

Thursday, December 16, 2010

Crazy Vim Stuff

Given a huge text file you want to extract some things from, here's how to delete all the lines that DON'T start with a regex in Vim:

:%s/^\(\(search text\)\@!.\)*$//g

then remove all the blank lines:

:g/^$/ d
(there's a space before the d)

then sort it with:
:sort

Help came from these pages:
http://vim.wikia.com/wiki/Search_and_replace
http://www.computing.net/answers/unix/delete-blank-line-thro-vi-editor/4552.html

No comments:

Post a Comment