4

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
  • 12,342
  • 27
  • 115
  • 173

1 Answers1

3

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 $?
quanta
  • 50,327
  • 19
  • 152
  • 213
  • since comment can't be taged properly, I updated my question with yours line, still no go though (( – alexus Feb 22 '13 at 03:11
  • is 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 Feb 22 '13 at 22:53
  • What do you mean by 'regex'? Isn't `(\n|.)*` a regex? – quanta Feb 23 '13 at 02:27
  • it'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` for `pcregrep` does, so my question is there a way to pass it some other way as part of regex? – alexus Feb 25 '13 at 00:34
  • I don't know what `simscan` is. Can you use `grep -P`? – quanta Feb 25 '13 at 08:36
  • there 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.. – alexus Feb 26 '13 at 22:09