On Thursday, June 14, 2012 11:15:10 PM UTC-5, ping wrote:
> still I'm thinking the exact syntax of this is kind of hard to 
> understand...for my uneducated eyes at least...
> 
> :g#classifier-group\>.*\n\s*[1-9]\d* packets, [1-9]\d* bytes#.,+1p
> 
> //this means we are "extracting" the matched lines only, means what ever 
> we'll do next based on this, we'll ignore those un-matched lines, it 
> seems not the case...
> :g#classifier-group\>.*\n\s*[1-9]\d* packets, [1-9]\d* bytes#
> 
> //this is very tricky part for me
> .,+1p
> 
> "." is "current line", for me this clearly should mean the "current 
> matched line", which is actually 2 real lines here since we are running 
> the multi-line regex.
> but obviously in this context, the "." was used to describe "only the 
> 1st line out of all matched lines", right?
> 

I think you may be confused about what a multi-line match does. The :g
command acts on the lines where a pattern matches. A pattern matches at a
single position: the position of the start of the match. The :g command
therefore only acts on the first line of a multi-line regex: the line
containing the position of the start of the match.

> and that "+1":
> the "1st matched line" plus "1 more" line, but shouldn't that offset 
> also be used from within the pool of matched lines? or regardless of 
> match or not?

No, it's a line offset. You're saying "print from the current line to one
below the current line", it has no concept of the matches to the :g command,
it fact it doesn't even know it's running in a :g command.

> my test shows if you put +2 it will print non-matched lines too:
> 

Yes, because there is only 1 matched line, as discussed above, and this is a
range of line numbers, not a range within the matched lines.

> :g/classifier-group.*\n.*[1-9]\d* packets, [1-9]\d* bytes/.,+2p
>   41     classifier-group dhcp entry 1
>   42       313 packets, 118332 bytes
>   43       rate-limit-profile dhcplimit        <--non-matched line
> 369     classifier-group jnpr-VIDEO-TRAFFIC entry 41
> 370       58658 packets, 8889186 bytes
> 371       rate-limit-profile video-upstream   <--non-matched line
> 
> so the right logic here looks is:
> 
> :g/.../ find some matched line(S),
> no matter how many lines got matched, take only 1st line, trash all others
> use that as the start of the range
> use another offset (here +1) based on original text (not matched lines), 
> as end of range
> print
> 

Basically...yes.

> 
> Then what if I want:
> the line containing classifier-group
> followed by a line x packets, y bytes
> followed by a line rate-limit-profile
> but I only want 1st & 3rd line under these constraint, since only these 
> are interested lines?
> 

so you'd want to match all 3 lines in your :g command:

:g#classifier-group.*\n.*[1-9]\d* packets, [1-9]\d* 
bytes.*\n.*rate-limit-profile#

then print just the first line and the 3rd line (but not the second line):

p | +2p

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