What are common pitfalls with grep command?

Common pitfalls with the grep command can lead to unexpected results and errors. Understanding these pitfalls can enhance your command-line skills and improve the accuracy of your searches.
grep, command line, common pitfalls, text search, Unix command, Linux command

        # Example of grep pitfalls
        # Searching for a pattern that is case-sensitive
        grep "error" logfile.txt  # This will only find "error" in lowercase, missing "Error" or "ERROR"

        # Using grep without recognizing special characters
        echo "Hello\nWorld" | grep "Hello"  # Doesn’t match with newline character between Hello and World

        # Incorrect regular expression usage
        grep "[a-z]" file.txt  # This will match any single lowercase letter instead of a full word

        # Not using the -r flag for recursive search
        grep "searchTerm" *  # This will only search in the current directory, missing subdirectories
    

grep command line common pitfalls text search Unix command Linux command