def find_word_in_file(file_path, search_word):
try:
with open(file_path, 'r') as file:
for line_number, line in enumerate(file, start=1):
if search_word in line:
print(f"Line {line_number}: {line.strip()}")
except FileNotFoundError:
print(f"The file {file_path} does not exist.")
except Exception as e:
print(f"An error occurred: {e}")
if __name__ == "__main__":
# Specify the path to your text file and the word you want to search for
file_path = 'index.txt' # Replace with your file path
search_word = 'specific' # Replace with the word you want to search for
find_word_in_file(file_path, search_word)
Click Run or press shift + ENTER to run code