INNER CODE UNIT · Python

search_content

AabyssZG/FindEverything · FindEverything-py2.py:23

def search_content(file_path, content):
    matching_lines = []
    try:
        with open(file_path, 'r') as file:
            for line_num, line in enumerate(file, 1):
                try:
                    if content in line:
                        matching_lines.append((line_num, line))
                except UnicodeDecodeError as e:
                    print("[-] Unicode decode error in file %s, line %d: %s" % (file_path, line_num, e))
        return matching_lines
    except:
        print("[-] Error file %s" % (file_path))

def write_to_file(output_file, file_path, matching_lines):
    with open(output_file, 'a') as f:
        f.write("[+] File Path: %s\n" % file_path)
        f.write("[=] Line Rows: %d\n" % len(matching_lines))

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…