Counting jump(no of lines) between first two 'String' occurrences in a file

前端 未结 4 1102
天命终不由人
天命终不由人 2021-01-22 09:27

I have a huge data file with a specific string being repeated after a defined number of lines.

counting jump between first two \'Rank\' occurrences. For example the file

4条回答
  •  误落风尘
    2021-01-22 10:08

    7 line of codes:

    count = 0
    for line in open("yourfile.txt"):
        if "Rank" in line: 
            count += 1
            if count > 1: break 
        elif count > 0: count += 1
    print count
    

提交回复
热议问题