pcregrep is not matching regex (multiline?)
6,031
one thing though each of these words are located on different lines, maybe that's why?
Yes. You have to insert a \n
and use -M
option to search for patterns that span line boundaries:
pcregrep -M -q '.*languager.*\n.*Preferences.*' input.file; echo $?
no, they're on few lines apart from each other (i don't have exact count and/or it can be changed, so I need regex for it)
OK. If so, try this:
pcregrep -M -q '.*languager(\n|.)*Preferences.*' input.file; echo $?
Author by
alexus
Consulting | alexus.biz Dmitry Chorine | LinkedIn a1exus (a1exus) on Twitter Verify a Red Hat Certified Professional | redhat.com
Updated on September 18, 2022Comments
-
alexus over 1 year
I don't understand why is first two is a match/hit, yet third is a miss?
-bash-3.2# cat 1361492805.M171838P41834.mx1.alexus.biz\,S\=12921\:2\,Sijm | pcregrep -q '.*languager.*' ; echo $? 0 -bash-3.2# cat 1361492805.M171838P41834.mx1.alexus.biz\,S\=12921\:2\,Sijm | pcregrep -q '.*Preferences.*' ; echo $? 0 -bash-3.2# cat 1361492805.M171838P41834.mx1.alexus.biz\,S\=12921\:2\,Sijm | pcregrep '.*languager.*Preferences.*' ; echo $? 1 -bash-3.2# cat 1361492805.M171838P41834.mx1.alexus.biz\,S\=12921\:2\,Sijm | grep -no 'language' 70:language -bash-3.2# cat 1361492805.M171838P41834.mx1.alexus.biz\,S\=12921\:2\,Sijm | grep -no 'Preferences' 149:Preferences -bash-3.2#
one thing though each of these words are located on different lines, maybe that's why?
* UPDATE *
-bash-3.2# pcregrep -M -q '.*languager.*\n.*Preferences.*' 1361492805.M171838P41834.mx1.alexus.biz\,S\=12921\:2\,Sijm ; echo $? 1 -bash-3.2#
-
alexus about 11 yearssince comment can't be taged properly, I updated my question with yours line, still no go though ((
-
alexus about 11 yearsis there a way to pass multiline somehow inside of regex? I'm using simscan and there is nowhere where I can specify that it's multi line other then inside of regex (simscan uses libpcre).
-
alexus about 11 yearsit's kind of hard to explain, but as I said I'm using simscan, it uses libpcre but it doesn't have a way for me to pass option as
-M
forpcregrep
does, so my question is there a way to pass it some other way as part of regex? -
Greg Petersen about 11 yearsI don't know what
simscan
is. Can you usegrep -P
? -
alexus about 11 yearsthere is NO command lines, simscan is a tool that works w/ qmail to help prevent spam, etc. I'm using regex to stop some of spam, but the problem is inside of simscan's config file, i can't pass -M or -p or whatever else other then regex itself, so I was thinking maybe there's a way to do it through regex..