What are grep options?

0972

Here are some commonly used grep options:

  1. -i: Perform case-insensitive searching.

    grep -i "pattern" filename
    
  2. -c: Count the number of matching lines.

    grep -c "pattern" filename
    
  3. -n: Display line numbers along with matching lines.

    grep -n "pattern" filename
    
  4. -v: Invert the match, showing lines that do not match the pattern.

    grep -v "pattern" filename
    
  5. -r or -R: Recursively search through directories.

    grep -r "pattern" directory/
    
  6. -l: Show only the names of files with matching lines.

    grep -l "pattern" *
    
  7. -e: Specify multiple patterns to search for.

    grep -e "pattern1" -e "pattern2" filename
    

These options can be combined to enhance the search capabilities of grep.

0 Comments

no data
Be the first to share your comment!