extracting a set amount of lines from a Text file - Python -
let imagine have text file following inside of it: (each line starts number , contains information next need)
1 325315
2 234265
3 345345
4 234234
5 373432
6 436721
7 325262
8 235268
how go extracting lines after number 3 , before number 6 example? while keeping other data held on same line.
i have large text file ~1000 lines, need extract lines starting 300 through 800. either extract or remove lines not need, either way ok.
thanks help
do this.
l = [line line in (open('xyz.txt','r')).readlines() if int(line.split()[0]) > 3 , int(line.split()[0]) < 6 ]
output:(output lines between 3 , 6)
c:\users\dinesh_pundkar\desktop>python c.py ['4 234234\n', '5 373432\n'] c:\users\dinesh_pundkar\desktop>
Comments
Post a Comment