Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
277 views
in Technique[技术] by (71.8m points)

regex - How to do multiline pattern matching in text file

I am getting the below file from test results and this file contains 100000 or more entries of test cases.

File Content:

Iteration is 1
Testcase is passed
Iteration is 2
Testcase is passed
Iteration is 3
Testcase is passed
Iteration is 4
Testcase is failed
Iteration is 5
Testcase is failed
Iteration is 6
Iteration is 7
Testcase is failed
Iteration is 8
Iteration is 9
Iteration is 10
Testcase is failed
Iteration is 11
Testcase is passed

For some test case iteration like 6, 8, 9 verdict is missing.There is no pass or fail for those iterations.

I just want to find for which iteration test case verdict is missing.

I opened file in gvim and tried to find and delete pattern like Iteration is .* .*passed and Iteration is .* .*failed but it didn't work .

Can anyone suggest how to find iterations for which there is no verdict like

Iteration is 6
Iteration is 8
Iteration is 9
question from:https://stackoverflow.com/questions/66057535/how-to-do-multiline-pattern-matching-in-text-file

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can do a "find" in any decent editor using the following regex:

Iteration is d+
Testcase is w+

and replace the matches with an empty string.

For example in vim, assuming the cursor is at the beginning of the file

:1,$s/Iteration is d+
Testcase is w+
//

does the trick.

Once done, the file will contain the lines with no tallying fail/pass result.

You could also use the same tactic to write a perl script - I leave that to you.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...