Search and extract results between two strings in multiple files
-
Hello Everyone,
I am trying to search and extract results between two strings in multiple files.
for example
i need to search string “Assign” between ‘PROCEDURE INIT-RECORD’ and ‘END PROCEDURE’, something like belowPROCEDURE INIT-RECORD
DEFINE variable a;
DEFINE variable b;
DEFINE variable c;Assign a = 4;
Assign b = 6;
c = a + b;
END PROCEDUREthe search results should retrieve
Assign a = 4, and
Assign b = 6.and similar Assign statements across multiple files within the PROCEDURE INIT-RECORD.
i tried NPP search using
(?s)(?<=PROCEDURE INIT-RECORD)(.+?)(?<=END PROCEDURE)the above regex search string selects the target procedure but i cannot copy the text from all the results.
Any help/pointers/ideas here will be appreciated.
-
@Amit-Pandey said in Search and extract results between two strings in multiple files:
Your regex seems ok, as a first step.
But use the Mark All function followed by Copy Marked Text and paste into a new N++ tab.
That way, in the new tab you haveAssign
data that only occurs between the specified delimiters; all others will not be in the new tab.
Then you can do a similar regex Mark operation forAssign
.
I think you know where to go from there.search and extract results between two strings in multiple files.
You will need to do the files one at a time, manually.
-
Hello, @amit-pandey, @alan-kilborn and All,
@amit-pandey, I suppose your need this regex technique
If we adapt this generic regex to your specific problem, we end with that functional regex :
MARK
(?-i:PROCEDURE INIT-RECORD|(?!\A)\G)(?s-i:(?!END PROCEDURE).)*?\K(?-si:Assign.+)
So :
-
Open your file in Notepad++
-
Move the cursor to its very beginning
-
Open the Mark dialog (
Ctrl+ M
) -
Untick ALL box options
-
Check the
3
optionsBookmark line
,Purge for each serch
andWrap around
-
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
Mark
contents (Ctrl + V
)
Here you are !
Best Regards
guy038
-
-
-
Hello @guy038 , @Alan-Kilborn
Thanks for your time in looking into this.
@Alan-Kilborn , the file volume is huge hence working this out for one file at a time is a challenge.
@guy038 , the regex search string did the trick, i used it in ‘Find in Files’ option.
The search results are giving me the first instance of the target string within the target procedure.
The results are far much better than what i was getting earlier with my search efforts.Although I still cannot get all the search results but i got a good perspective on my search results
-
Hi, @amit-pandey, @alan-kilborn and All,
@amit-pandey, you said :
Although I still cannot get all the search results but i got a good perspective on my search results
This means that your initial example is totally insufficient and that we need some other blocks
PROCEDURE INIT-RECORD ....... END PROCEDURE
that allow us to build the appropriate regex which will match all the expected results !So, just add a longer exemple, which describe most of the cases which may occur, using the
</>
function, in your answer !BR
guy038
-
Hello @guy038 ,
My bad, i misinterpreted your reply and went into a different direction.
(also had to upgrade my NPP (upgraded to v8.4.9) to reflect ‘Copy Marked text’ option".I have now achieved what is required.
Here are the steps which i followed
- Search for Regex String ‘PROCEDURE INIT-RECORD|ASSIGN|END PROCEDURE’ across the files
- Copied the search result in a new window
- Applied regex search string provided by you in the earlier reply’ and followed the provided steps
- All the target keywords within the target procedure were marked
- Used ‘Copy Marked Text’ option and got my results
Thanks a lot for your help.