Find line before specific text

  • 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.

    EL: 3483

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



    EL; 3484

    EL: 3485

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



    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”.

  • 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


Log in to reply