Search code examples
vim

Vim: find lines with less occurrences of string


In a data file I need to find all lines that contain less than 10 times the pattern |^| I need them in two ways:

  1. a search, so I can go through the file and examine the data
  2. as a list to be copied, including the next line

I use Gvim in Windows.

So far I've tried along the lines of:

/[|^|]{,9}
/[|^|]*{,9}
:g/\v(\|[^|^|]*){,9}/p

Is anyone able to help me?

Edit: an example (as real data is not allowed to be used)

abc|^|def|^|ghi|^|jkl|^|mno|^|pqr|^|stu|^|vwx|^|yza|^|bcd|^|efg
abc|^|def|^|ghi|^|jkl|^|mno|^|pqr|^|stu|^|vwx|^|yza|^|
bcd|^|efg
abc|^|def|^|ghi|^|jkl|^|mno|^|pqr|^|stu|^|vwx|^|yza|^|bcd|^|efg

Final solution:

:v/\v(\|\^\|.*){10}

Solution

  • I tried this one. I think it will help.

    /\(|^|.*\)\{10}

    or with \v

    /\v(\|\^\|.*){10}