0

How can I cut specific text from a python file (around 150 000 000 lines)? I mean that program has to find one word and ending word and cut it what is between these lines. I was trying something like that:

with bz2.BZ2File(file, 'r','utf-8') as f:
    for line in f:
        counter += 1
        if line.strip() == '<title>Viriato da Cruz</title>':  #or whatever title you need
            break
        elif counter > 1000:
            break
            print('bla')
    for line in f:
        counter += 1
        if line.strip() == '</text>' :
            break
        print(line)
fedorqui
  • 275,237
  • 103
  • 548
  • 598
Oliwia
  • 1
  • 2
  • write your input and expected output and show your efforts too – sachin dubey Jul 10 '18 at 07:26
  • 1
    What did you try? – DYZ Jul 10 '18 at 07:26
  • 1
    open file and read each lines `lines = [line.rstrip('\n') for line in file]` and then do ur stuffs. Take a look at ,https://stackoverflow.com/q/32015356/4628154. – ramganesh Jul 10 '18 at 07:30
  • 1
    @Oliwia do not place code in comments, please edit the original question. Ensure you update your question with sample-input, sample-output, your-code. And please ask specific questions about what goes wrong with your code.... thank you. – Edwin van Mierlo Jul 10 '18 at 07:36

0 Answers0