Ok, so another adventure today… the story begins with a MySQL dump of a Drupal database, and inserts so large they span more than a screen. This ended with me wishing for a less cluttered dump, say, with only the “INSERT INTO …” statements left in the file.
From a thread I recently read on StackOverflow.com, I’d gotten some new insights into how to do stuff, which was taken even further today when I sought out how to find all lines not containing some string (i.e. “INSERT INTO”) and remove it:
:g/FOO
will find all lines containing “FOO”. Similarly,
:g/^FOO
will find all lines beginning with ” FOO”. Now to the cool parts:
:g!/FOO
will find us all lines NOT containing “FOO”.
And finally:
:g!/FOO/d
will delete all lines NOT containing “FOO”.
:g!/^INSERT INTO/d
