regex - finding lines that contain n occurences of a certain pattern -
i have file containing lines like
a,b,1,2,3,$long,6,"a","",$long,,,,"abc",,$long,,,, e,f,2,3,4,$long,$long,$long,$long,,,"a","string";123456,,,1,2
my goal find lines containing n occurences of pattern "$long".
anyone knowing grep regex match?
you don't need regex this. awk
can use $long
field separator , check how many fields each line has:
awk -v count=3 'begin {fs="\\$long"} nf==(count+1)' file
test
$ awk -v count=3 'begin {fs="\\$long"} nf==(count+1)' a,b,1,2,3,$long,6,"a","",$long,,,,"abc",,$long,,,, $ awk -v count=4 'begin {fs="\\$long"} nf==(count+1)' e,f,2,3,4,$long,$long,$long,$long,,,"a","string";123456,,,1,2 $ awk -v count=5 'begin {fs="\\$long"} nf==(count+1)' $
Comments
Post a Comment