Community
    • Login

    Find line before specific text

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    2 Posts 2 Posters 720 Views 1 Watching
    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 Offline
      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 Offline
        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

        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

        With your input, this post could be even better 💗

        Register Login
        • First post
          Last post
        The Community of users of the Notepad++ text editor.
        Powered by NodeBB | Contributors