I have a huge text file where records are identified by the string MSH.
I need to find the 200th record. I am hoping that there is a regular expression I can use in Notepad++ that would enable me to find the 200th occurrence of the string MSH.
If your file is just an enormous one-liner delimited by the string "MSH" you could use this in a regular expression find.
But, make sure your cursor is at the beginning of the file or it'll just search for the next 200th record from where you started!
Find:
((.*?)MSH){199}
This should highlight the first 199 records, so the next unhighlighted record is the 200th.
OR, take it a bit further!
Again, in a regular expression find replace, again make sure your cursor is at the beginning of the file.
Find:
((.*?)MSH){199}((.*?)MSH{1}).*
Replace:
$3
Should replace the entire contents of the window with just the 200th record.
N.B: This assumes that the string "MSH" is not part of any of the records in the file.
As a footnote, I strongly doubt any of this is quick over a large file. Scripting is almost certainly a better option. Or possibly even dropping it into Excel and using text-to-columns.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With