question on write the result of first 50 matched result to txt
I am reading a txt file (called file.txt) and filter through the entire file looking for lines start with “>” symbol. I used regular expression to find line starts with “>”. The output of the program is the first 5 matched results with “>”. I attached my code with this post and sample input.
1 #!/usr/bin/env python
2 # testing
3 import re
4
5 match = ”
6 n = 5
7 file = open(“file.txt”,”r”)
8 for i in range(n):
9 if re.match(‘^>’,i):
10 match += i
11
12 out_file = open(“outfile.txt”,’w’)
13 out_file.write(header)
14 out_file.close()