Notepad++ Search And Replace Multiple Text Lines

前端 未结 1 1458
天涯浪人
天涯浪人 2021-01-29 04:12

I have thousands of these in many different rules rules

edit 1698

set src-address \"172.29.44.51/32\"

set dst-address \"172.29.44.67/32\" 

set service \"tcp-1         


        
相关标签:
1条回答
  • 2021-01-29 05:17

    Here is a notepad++ only solution. It is using macros, because you say you have many different rule files.

    1. Macro -> Start Recording, now everything is recorded to a macro
      1. First Replace to mark the start of a set service block:
        • Press Ctrl-Pos1, to go to the beginnig of current file.
        • Search -> Replace...:
          Find What: ^(?!set service).+?\r\nset service
          Replace With: \1first set service\3 check Regular Expression in the lower left
        • Press Replace All
      2. Second Replace to join a set service block with the starting line:
        • Press Ctrl-Pos1, to go to the beginnig of current file.
        • Search -> Replace...:
          Find What: \r\nset service
          Replace With: `` (nothing) check Extended in the lower left
        • Press Replace All
      3. Third Replace to remove the tag in the starting line:
        • Press Ctrl-Pos1, to go to the beginnig of current file.
        • Search -> Replace...:
          Find What: ^first set service
          Replace With: set service check Regular Expression in the lower left
        • Press Replace All
    2. Macro -> Stop Recording
    3. Macro -> Save Current Recorded Macro, give it a name and create a keyboard shortcut for it.
    4. Test the Macro. If it works, continue, else delete it and restart recording.

    Now you can open all your rule files and apply the Macro to each file. If you need to delete the macro, you find it under Macro -> Modify Shortcut/Delete Macro.

    Edit: here is a screenshot to debug the problems with the zero matches you write about in the comments: , please note the marked sections:

    • \r\n in the Find expression
    • Dos\Windows as lineending type in the status bar
    • Regular expression is checked in the lower left
    • the region that is matched by the search in the file area

    The number of lines have to be modified:

    The result of suggested search Regex:

    0 讨论(0)
提交回复
热议问题