Vim multiple filtering of a file, with 2 filters based upon number values -


i not know if title sound adequate …

let have file (> 1000 lines) homogeneous structure throughout consisting of 3 "fields" separated space :

1. integer (negative or positive)    <space> 2. integer (negative or positive)    <space> 3. text (description) 

the integers >-10000 , < 10000

my problem : how can i

a) filter file criteria such "1st integer <= 1000" , "2nd integer >=250" , "text contains : boston or new-york"

b) , put subset in new buffer, allowing me read results , results of filter(s) ?

i wish vim only, not knowing if feasible or reasonable (anyway above skills)

thanks


@fdinoff : sorry, should have done suggest, of course :

it chronology startdate, enddate, , description :

1 -200 -50 period 1 in italy 2 -150 250 period 1 in greece 3  -50  40 period 2 in italy  4   10  10 event in italy 5   20  20 event 2 in greece 

the filter : filter items (to mimic sql) startdate <=-50 , enddate >=0 , description contains greece, resulting filter => line 2

the following generic form match numeric parts of format:

^\s*-\?\d\+\s\+-\?\d\+ 

to implement restrictions on numbers, replace each -\?\d\+ more specific pattern. example, <= -50:

-\([5-9][0-9]\|[1-9][0-9]\{2,}\) 

that is, - followed either 2 digit number first digit >= 5, or >= 3 digit number.

similarly, >= 250:

\(2[5-9][0-9]\|[3-9][0-9]\{2,}\) 

combining two:

^\s*-\([5-9][0-9]\|[1-9][0-9]\{2,}\)\s\+\(2[5-9][0-9]\|[3-9][0-9]\{2,}\) 

if need filter pattern in description, append that:

^\s*-\([5-9][0-9]\|[1-9][0-9]\{2,}\)\s\+\(2[5-9][0-9]\|[3-9][0-9]\{2,}\)\s\+.\{-}greece 

.\{-} lazy version of .*.

to filter pattern , write output file, use following:

:g/pattern/.w filename 

thus, filter "first number <= -50 , second number >= 250 , 'greece' in description" , write output greece.out:

:g/^\s*-\([5-9][0-9]\|[1-9][0-9]\{2,}\)\s\+\(2[5-9][0-9]\|[3-9][0-9]\{2,}\)\s\+.\{-}greece/.w greece.out 

more complex ranges make more ridiculous; you're better off parsing file , filtering other regex.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -