Large File

Given a file of size 100GB, how will you find the keyword “Error” or “Exception” in the file ???

1 Like

The following should work. This only loads the file line by line, and garbage collects the previous lines.

with open("large_file.txt") as f:
    for line in f:
        search_for_keywords(line)

Depending on what you want to do, it may be easier to do with grep than with Python. If I only want to find the lines, I would just write the following in a terminal:

grep "Error\|Exception" large_file.txt
2 Likes

Thanks for the answer :slight_smile: It is asked to me in my assignment and I couldn’t tell the correct answer …Thanks again for so prompt reply :slight_smile:

//