In shell, cat filename | grep -i error would return content from the file having the string 'error' .
What is the Python equivalent of this ?
In shell, cat filename | grep -i error would return content from the file having the string 'error' .
What is the Python equivalent of this ?
Open the file, iterate over all the lines and print the lines only if it contains error
.
with open(file) as f:
for line in f:
if 'error' in line:
print(line)
for case-insensitive match,
with open(file) as f:
for line in f:
if re.search(r'(?i)error', line):
print(line)