Find a pattern in a file
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
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?
PeterJones last edited by
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
0x85806014and the second line contains
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 =
- 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
F2shortcut, 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.
- Find What =
thats seems to work perfectly
Thank you very much
i test it and it works perfect. But when i test it i see another issue i need.
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?
Scott Sumner last edited by
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,…”
“evolving problem syndrome”
Sorrs, but i dont now what regex is?
Meta Chuh last edited by
i’ve just added eps to my daily job dictionary 😉👍
PeterJones last edited by PeterJones
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.
Scott Sumner last edited by
Damn, this Community forum is getting all HARD CORE ! (I like it)