Find shortest matches between two strings

后端 未结 4 1251
走了就别回头了
走了就别回头了 2020-11-22 16:30

I have a large log file, and I want to extract a multi-line string between two strings: start and end.

The following is sample from the

4条回答
  •  旧巷少年郎
    2020-11-22 17:33

    Do it with code - basic state machine:

    open = False
    tmp = []
    for ln in fi:
        if 'start' in ln:
            if open:
                tmp = []
            else:
                open = True
    
        if open:
            tmp.append(ln)
    
        if 'end' in ln:
            open = False
            for x in tmp:
                print x
            tmp = []
    

提交回复
热议问题