Pcregrep is not matching regex (multiline?)

pcreregex

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#

Best Answer

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 $?
Related Topic