On 11/28/2010 09:07 AM, Jeri Raye wrote:
I was wondering to search for certain patterns in the log file and
provide a start and end mark for the interresting stuff.
And then delete all that isn't in the selected sections.
Is that possible?

While it's a little hard to determine the particulars from your description and pseudo-examples, the general process I use to do something similar looks like

  :g/interesting/sil! ?start?,/end/s/^/XXX/
  :v/^XXX/d
  :%s/^XXX

This searches for every line matching the pattern "interesting", then searches backwards for the pattern "start" as the beginning of the range, and forward to the pattern "end". With each of those start...end ranges, it tacks on a unique prefix (in this case, "XXX") The "sil!" is just to prevent it from reporting action on every matching line because it annoys me :)

Now that you've found and marked the interesting stuff, you can delete the rest (the "v/^XXX/d").

Finally, remove the "XXX" marker leaving you with just what you want.

Each of those patterns can be an arbitrary regexp, so you can use multiple conditions:

  :g/foo\|bar\|baz/sil! ...

Alternatively, I'll use ">" as my command instead of "s/^/XXX" to indent the lines of interest (best done with 'noet' and 'sw'='ts' so you get one tab of indent), delete the non-indented lines, and then un-indent the indented lines:

  :g/interesting/sil! ?start?,/end/>
  :v/^\t/d
  :%<

Hope this gives you a general pattern you can use.

-tim






--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Reply via email to