On Friday, June 15, 2012 9:53:45 AM UTC-5, ping wrote:
> 
> [ping] this I tested, yes it works!
> still I think ... here we happen to know which line out of the original 
> text will be the matched lines, so we can just specify the line with a 
> static number there...what if we don't know (or hard to count)?
> 

You might be able to do it using a search pattern as the range to a print 
command.

> say from these texts snips:
> 
>      classifier-group dhcp entry 1      <----wanted block
>        313 packets, 118332 bytes
>        rate-limit-profile dhcplimit
>          committed rate: 1280 bps, committed burst: 8192 bytes  <--wanted
>          excess burst: 0 bytes
>          committed: 313 packets, 118332 bytes, action: transmit  <-wanted
>          conformed: 0 packets, 0 bytes, action: drop
>          exceeded:  0 packets, 0 bytes, action: drop
>      classifier-group jnpr-VIDEO-TRAFFIC entry 1 <--not wanted block
>        0 packets, 0 bytes
>        rate-limit-profile video-upstream
>          committed rate: 218000 bps, committed burst: 32000 bytes
>          excess burst: 0 bytes
>          committed: 0 packets, 0 bytes, action: transmit
>          conformed: 0 packets, 0 bytes, action: drop
>          exceeded:  0 packets, 0 bytes, action: drop
>      classifier-group jnpr-VIDEO-TRAFFIC entry 2 <--not wanted block
>        0 packets, 0 bytes
>        rate-limit-profile video-upstream
>          committed rate: 0 bps, committed burst: 0 bytes
>          excess burst: 0 bytes
>          committed: 0 packets, 0 bytes, action: transmit
>          conformed: 0 packets, 0 bytes, action: drop
>          exceeded:  0 packets, 0 bytes, action: drop
> 
> it is composed by a lot of (around 41 or sometime far more) 
> "classifier-group" blocks.
> 

But for something this complex I'd probably just write a while loop in a *.vim 
file, like:

let lineNum = 1
let savedLine = ""
while lineNum < line('$')
  let lineTxt = getline(lineNum)
  if lineTxt =~ 'some pattern of your choosing'
    let savedLine = lineTxt
  elseif lineTxt =~ 'some other pattern'
    echo savedLine
    echo lineTxt
  endif
  let lineNum += 1
endwhile

Then use :source whatever.vim on the file you want to parse.

If you use this often you can place it in a function and create a command and 
put it in your .vimrc somewhere:

function! MyPrettyParser()
  ...while loop from above...
endfunction

command! ParseSomething call MyPrettyParser()

-- 
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