• Login
Community
  • Login

Find a pattern in a file

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
9 Posts 4 Posters 2.0k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W
    Werner Scharnhorst
    last edited by Dec 3, 2018, 2:52 PM

    Hello

    i have a logfile with many errors

    12.10.2015 13:02:40 0x85806013 appAPP minor Error
    12.10.2015 13:02:42 0x83800023 appAPP Warning
    12.10.2015 13:02:42 0x85806014 appAPP minor Error
    12.10.2015 13:02:42 0x85806013 appAPP minor Error
    12.10.2015 13:02:45 0x83800023 appAPP Warning
    12.10.2015 13:02:45 0x85806011 appAPP minor Error

    now i want to find a special pattern

    0x85806014
    0x85806013

    and that a Lines a marked with a color.
    But not lines that contain only one of the codes. Only the lines where both codes stand together as in the example

    How can i do this?

    best regards
    Werner

    1 Reply Last reply Reply Quote 0
    • P
      PeterJones
      last edited by Dec 3, 2018, 3:30 PM

      Let me see if I understand what you want correctly: I believe you want to mark/highlight/select a two-line combination, where the first line contains 0x85806014 and the second line contains 0x85806013.

      If this is accurate, and using a modified dataset so that it has ones that will match and partial-matches that won’t:

      12.10.2015 13:02:40 0x85806013 appAPP minor Error       -- does not match: just has the second hex value
      12.10.2015 13:02:42 0x83800023 appAPP Warning
      12.10.2015 13:02:42 0x85806014 appAPP minor Error       -- match#1
      12.10.2015 13:02:42 0x85806013 appAPP minor Error       -- match#1 continued
      12.10.2015 13:02:45 0x83800023 appAPP Warning
      12.10.2015 13:02:45 0x85806011 appAPP minor Error
      12.10.2015 13:02:42 0x85806014 appAPP minor Error       -- does not match: just has the first hex value, but next line doesn't have second
      12.10.2015 13:02:42 0x83800023 appAPP Warning
      12.10.2015 13:02:42 0x85806014 appAPP minor Error       -- match#2
      12.10.2015 13:02:42 0x85806013 appAPP minor Error       -- match#2 continued
      12.10.2015 13:02:42 0x83800023 appAPP Warning
      

      With that data, I then do Search > Mark, with

      • Find What = (?-s)^.*0x85806014.*\R.*0x85806013.*
      • Search Mode = ☑ Regular Expression

      That will highlight all of the matching pairs of lines.

      If you also want to be able to easily jump between pairs, you can use the addional option:

      • ☑ Bookmark line

      This will put a round bubble in the left column… you can use Search > Bookmark > Next Bookmark (F2) (or the F2 shortcut, if it’s set up in Shortcut Mapper , which I think is a default) to move forward to the next bookmarked pair.

      -----
      FYI: if you have further regex needs, study this FAQ and the documentation it points to. Before asking a new regex question, understand that many of us will expect you to show what data you have (exactly), what data you want (exactly), what regex you already tried (to show that you’re showing effort), why you thought that regex would work (to prove it wasn’t just something randomly typed), and what data you’re getting with an explanation of why that result is wrong. When you show that effort, you’ll see us bend over backword to get things working for you. If you need help formatting the data so that the forum doesn’t mangle it (so that it shows “exactly”, as I said earlier), see this help-with-markdown post , where @Scott-Sumner gives a great summary of how to use Markdown for this forum’s needs.

      Please note that for all “regex” queries – or queries where you want help “matching” or “marking” or “bookmarking” a certain pattern, which amounts to the same thing – it is best if you are explicit about what needs to match, and what shouldn’t match, and have multiple examples of both in your example dataset. Often, what shouldn’t match helps define the regular expression as much or more than what should match.

      1 Reply Last reply Reply Quote 2
      • W
        Werner Scharnhorst
        last edited by Dec 4, 2018, 9:07 AM

        Hello

        thats seems to work perfectly
        Thank you very much

        best regards
        Werner

        1 Reply Last reply Reply Quote 0
        • W
          Werner Scharnhorst
          last edited by Dec 4, 2018, 12:11 PM

          Hello

          i test it and it works perfect. But when i test it i see another issue i need.
          For example
          Now i look for a pattern which is in two successive lines. But can i make a search where i said that 0x85806014 is present in a line but the next line or in the line before does not included the 0x85806013 code?

          best regards
          Werner

          S 1 Reply Last reply Dec 4, 2018, 1:01 PM Reply Quote 0
          • S
            Scott Sumner @Werner Scharnhorst
            last edited by Dec 4, 2018, 1:01 PM

            @Werner-Scharnhorst

            It sounds like you have “evolving problem syndrome”. You asked for one thing, someone provided it, and now you want to change what you asked for (at least I think that is correct as it is tough to understand your most recent post).

            Now that you know (from the first response) this is a “regular expression” or “regex” problem, and your question is about that (rather than being about Notepad++, which is what this forum is about), perhaps taking further queries to a site more dedicate to regular expressions is appropriate.

            Reread @PeterJones 's posting where he says “FYI: if you have further regex needs,…”

            M 1 Reply Last reply Dec 4, 2018, 3:15 PM Reply Quote 2
            • W
              Werner Scharnhorst
              last edited by Dec 4, 2018, 2:54 PM

              @Scott-Sumner said:

              “evolving problem syndrome”

              Sorrs, but i dont now what regex is?

              1 Reply Last reply Reply Quote 0
              • M
                Meta Chuh moderator @Scott Sumner
                last edited by Dec 4, 2018, 3:15 PM

                @Scott-Sumner
                i’ve just added eps to my daily job dictionary 😉👍

                1 Reply Last reply Reply Quote 2
                • P
                  PeterJones
                  last edited by PeterJones Dec 4, 2018, 3:29 PM Dec 4, 2018, 3:28 PM

                  @Werner-Scharnhorst ,

                  A “regex” is a “regular expression”, which is the “flavor” of search that was employed by my solution for your original question. This would have been explained to you if you had followed the links-for-further learning that I gave you in my previous post.

                  meta advice: Given that your second query didn’t improve compared to your first – it didn’t even show that you’d read the suggestions directly in my post, let alone reading the supplemental links – you appear to be evidencing a desire to have someone else do the work for you, rather than showing a willingness to learn and take advice. Whether this was your intention or not, whether it accurately describes your desire or your willingness, it’s how you are coming across to others. If you continue to present yourself in this manner, you will quickly wear out your welcome in this help forum and likely in whatever help-forums you frequent now or in the future. Good luck.

                  Generic advice for your second problem, and all future match/search/replace problems: whenever I have a new match or search or search/replace problem, the first thing I do is think “what exactly do I want to match? what don’t I want to match? what steps would I take as I’m mentally comparing a piece of text to my requirements to see whether it matches?” These will give you a good framework for then translating your requirements into the specific syntax of whatever match/search/replace engine you are using – in this case, it’s a flavor of PCRE, as described in the links I’ve already pointed you to. Once you’ve done all these steps, and have a search expression that you think would do what you want, but for some reason isn’t, then your effort will be rewarded when you ask someone, and get an answer that helps you fix whatever issue you’re having in the moment, and will help you learn more about how to do your own regex in the future – you will have made it easier for someone to help you, you will have gotten help on the immediate problem, and you would have learned more for the future: a win/win/win situation.

                  1 Reply Last reply Reply Quote 7
                  • S
                    Scott Sumner
                    last edited by Dec 4, 2018, 4:00 PM

                    Damn, this Community forum is getting all HARD CORE ! (I like it)

                    :-)

                    1 Reply Last reply Reply Quote 0
                    5 out of 9
                    • First post
                      5/9
                      Last post
                    The Community of users of the Notepad++ text editor.
                    Powered by NodeBB | Contributors