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.
Example:
EL: 3483EL: 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”.
-
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 searchandWrap around -
Un-tick all other box options
-
Select the
Regular expressionsearch mode -
Click on the
Mark Allbutton -
Click on the
Copy Marked Textbutton -
Open a new tab (
Ctrl + N) -
Paste the clipboard contents (
Ctrl + V)
-
Et voilà !
After clicking on the
Mark Allbutton you may, either :-
Right-click into the bookmark margin and choose the
Copy bookmarked Linesoption -
Use the menu option
Search > Bookmark > Copy Bookmarked Lines
Best Regards
guy038
-