python - Search File And Find Exact Match And Print Line? - Stack Overflow

PHOTO EMBED

Tue Sep 10 2024 08:15:03 GMT+0000 (Coordinated Universal Time)

Saved by @rhce143 #python

def lines_that_equal(line_to_match, fp):
    return [line for line in fp if line == line_to_match]

def lines_that_contain(string, fp):
    return [line for line in fp if string in line]

def lines_that_start_with(string, fp):
    return [line for line in fp if line.startswith(string)]

def lines_that_end_with(string, fp):
    return [line for line in fp if line.endswith(string)]
content_copyCOPY

https://stackoverflow.com/questions/15718068/search-file-and-find-exact-match-and-print-line