Jump to content

Grep

From Squishu Wiki

General

  • The grep utility searches any given input files, selecting lines that match one or more patterns. By default, a pattern matches an input line if the regular expression (RE) in the pattern matches the input line without its trailing newline. An empty expression matches every line. Each input line that matches at least one of the patterns is written to the standard output
  • -l (dash L) Only the names of files containing selected lines are written to standard output
  • While find looks for files, grep searches files for strings
    • Often the exec command for find is grep
    • general regular expression parser

Syntax

  • grep [options] PATTERN [files]

Options

  • -c
    • don't print matching lines, print a count of the lines that match
  • -E
    • turns on extended expressions
  • -h
    • doesn't print the name of the file the string was found in
  • -i
    • ignore case
  • -l
    • lists the names of files with matching lines, but not the matched line
  • -v
    • inverts the matching pattern to selet nonmatching lines rathern than matching ones