Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

fetch lines with two or three words

Last post 07-31-2008, 2:12 AM by killahbeez. 3 replies.
Sort Posts: Previous Next
  •  07-30-2008, 5:08 PM 44770

    fetch lines with two or three words

    Hi I am looking for a way I can use regex with grep (unix) or textpad (windows) to look information from specific lines.

    Currently my application logs lots of information and logs are very huge. I need to look for specific words to locate if that is the particular line I am looking for.

    Words are like "NOAM.CORP.COM", "TOTAL" and "LOGIN". If all these three words are present then I need to pick that line.

    Please advise a regex here.

    Thanks,

    Praveen.

     

  •  07-30-2008, 5:40 PM 44771 in reply to 44770

    Re: fetch lines with two or three words

    There has to be a better way, but from what I understand of grep's regex support:

    .*\bNOAM\.CORP\.COM\b.*\bTOTAL\b.*\bLOGIN\b|.*\bTOTAL\b.*\bLOGIN\b.*\bNOAM\.CORP\.COM\b|.*\bLOGIN\b.*\bNOAM\.CORP\.COM\b.*\bTOTAL\b|.*\bTOTAL\b.*\bNOAM\.CORP\.COM\b.*\bLOGIN\b|.*\bNOAM\.CORP\.COM\b.*\bLOGIN\b.*\bTOTAL\b|.*\bLOGIN\b.*\bTOTAL\b.*\bNOAM\.CORP\.COM\b

    (pattern edited)


  •  07-30-2008, 5:48 PM 44774 in reply to 44771

    Re: fetch lines with two or three words

    On platforms that support lookahead constructs:

    (?=.*\bNOAM\.CORP\.COM)(?=.*\bTOTAL\b)(?=.*\bLOGIN\b).*

    or:

    (?=.*\bNOAM\.CORP\.COM)(?=.*\bTOTAL\b)(?=.*\bLOGIN\b).*?(?=\r?\n|$)


  •  07-31-2008, 2:12 AM 44793 in reply to 44774

    Re: fetch lines with two or three words

    grep -Pi '(?=.*\bNOAM\.CORP\.COM\b)(?=.*\bTOTAL\b)(?=.*\bLOGIN\b)' test.txt

     

    -P, --perl-regexp         PATTERN is a Perl regular expression

     -i, --ignore-case         ignore case distinctions

View as RSS news feed in XML