Community
    • Login

    Find line before specific text

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    2 Posts 2 Posters 343 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.
    • Elise BaribaultE
      Elise Baribault
      last edited by

      Hi

      I need the line number (or the text on that line) two rows above a certain word. I have a file with hundreds of thousands of lines, and I don’t want to go through it by hand.

      Example:
      EL: 3483

      EL: 3484 (<- this is the line/value I want)

      8

      ABNORMAL PROGRAM STOP

      EL; 3484

      EL: 3485

      EL: 3486 (<- this is the line/value I want)

      8

      ABNORMAL PROGRAM STOP

      When I Ctl+F the data, it shows me the row where “Abnormal program stop” is, over 7,000 occurrences. But I am looking for the text two rows above this message.

      I need the number specifically associated with this error message. There are other lines “EL: 3484” that do not have the error message after, so I can’t search just for the text “EL: 3484”.

      1 Reply Last reply Reply Quote 0
      • guy038G
        guy038
        last edited by guy038

        Hello, @elise-baribault and All,

        Not difficult with regular expressions !

        • Open the Mark dialog ( Ctrl+ M )

          • SEARCH (?-si)^EL[:;]\x20\K\d+(?=\R.+\RABNORMAL PROGRAM STOP$)

          • Tick the three options Bookmark line, Purge for each search and Wrap around

          • Un-tick all other box options

          • Select the Regular expression search mode

          • Click on the Mark All button

          • Click on the Copy Marked Text button

          • Open a new tab ( Ctrl + N )

          • Paste the clipboard contents ( Ctrl + V )

        Et voilà !

        After clicking on the Mark All button you may, either :

        • Right-click into the bookmark margin and choose the Copy bookmarked Lines option

        • Use the menu option Search > Bookmark > Copy Bookmarked Lines

        Best Regards

        guy038

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