How to delete lines without String



  • Hello community,

    I have various logfiles which I want to filter with a grep-like functionality.

    The way I did it before is:

    • Mark the word / string

    • Search/Mark

    • enable option “Bookmark line”
      – mark all
      – close

    • Search/Bookmark

    • “Remove Unmarked lines”

    For this procedure I recorded a macro and stored it in shortcuts.xml:

    <Macros>
    <Macro name=“Trim Trailing and save” Ctrl=“no” Alt=“yes” Shift=“yes” Key=“83”>
    <Action type=“2” message=“0” wParam=“42024” lParam=“0” sParam="" />
    <Action type=“2” message=“0” wParam=“41006” lParam=“0” sParam="" />
    </Macro>
    <Macro name=“grep01” Ctrl=“no” Alt=“no” Shift=“no” Key=“0”>
    <Action type=“3” message=“1700” wParam=“0” lParam=“0” sParam="" />
    <Action type=“3” message=“1601” wParam=“0” lParam=“0” sParam=“IM1 001” />
    <Action type=“3” message=“1625” wParam=“0” lParam=“0” sParam="" />
    <Action type=“3” message=“1702” wParam=“0” lParam=“784” sParam="" />
    <Action type=“3” message=“1701” wParam=“0” lParam=“1615” sParam="" />
    <Action type=“2” message=“0” wParam=“43051” lParam=“0” sParam="" />
    </Macro>

    Is it possible to replace the string “IM1 001” with a wildcard, or the actual marked text and then just press a combination to do the job?

    p.s. How do i format code snippets here?



  • @Sammy-Bresel said:

    Is it possible to replace the string “IM1 001” with a wildcard, or the actual marked text?

    Unfortunately not. Searches recorded as macros always have all of their parameters hard-wired. It would be awesome to be able to embed a special string in the findwhat and replacewith boxes such that when the macro is run a popup box would prompt for a bit of text to embed within a larger regex, but no such luck. Such a mechanism could also be used to get clipboard data to embed.

    However, some options are available to you, that are, admittedly, a bit more complex. And by this I mean “scripting”. It is fairly easy to script a custom, promptable search or replace option. One downside of this is that it can’t (easily) use the findresult panel to show the fruits of that labor.

    Although, thinking about it now, a script could open the find window, populate all of the UI elements, and then push one of the find window buttons that causes findresult panel to be populated. Scripting is (almost) all powerful. :)

    How do i format code snippets here?

    There’s a few ways. Easiest to explain and understand is to indent your code (all of it) with 4 leading spaces. Then it will appear in a black box (and be UNTOUCHED by this website) like so:

    <Macros>
    <Macro name=“Trim Trailing and save” Ctrl=“no” Alt=“yes” Shift=“yes” Key=“83”>
    <Action type=“2” message=“0” wParam=“42024” lParam=“0” sParam="" />
    <Action type=“2” message=“0” wParam=“41006” lParam=“0” sParam="" />
    </Macro>


  • Thank you, i will consider a script then.



  • @Sammy-Bresel

    Since you are “script willing”, I might suggest Pythonscript (which is super if you already know Python) and a script to get you going with search/replace that could be adapted to what you want might be found here: https://notepad-plus-plus.org/community/topic/16942/pythonscript-any-ready-pyscript-to-replace-one-huge-set-of-regex-phrases-with-others/


Log in to reply