Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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#
share|improve this question
    
Are they not located in continuous lines? –  quanta Feb 22 '13 at 3:18
    
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) –  alexus Feb 22 '13 at 3:20
    
updated my answer. –  quanta Feb 22 '13 at 3:25

1 Answer 1

up vote 1 down vote accepted

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 $?
share|improve this answer
    
since comment can't be taged properly, I updated my question with yours line, still no go though (( –  alexus Feb 22 '13 at 3:11
    
thank you, that what I was missing/looking for! –  alexus Feb 22 '13 at 3:35
    
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 2: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 0:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.