Print lines that match patterns.

Synopsis

grep [OPTION]... PATTERN [FILE]...

Description

Search for lines matching a pattern in files or standard input. By default uses basic regular expressions. Runs in the just-bash WASM shell inside SLICC, operating on a virtual filesystem backed by IndexedDB.

Options

-E, --extended-regexp Interpret PATTERN as an extended regular expression.

-P, --perl-regexp Interpret PATTERN as a Perl regular expression.

-F, --fixed-strings Interpret PATTERN as a set of fixed strings.

-i, --ignore-case Ignore case distinctions in patterns and input.

-v, --invert-match Select non-matching lines.

-w, --word-regexp Match only whole words.

-x, --line-regexp Match only whole lines.

-c, --count Print only a count of matching lines per file.

-l, --files-with-matches Print only names of files containing matches.

-L, --files-without-match Print only names of files with no matches.

-m NUM, --max-count=NUM Stop reading after NUM matching lines.

-n, --line-number Prefix each line with its line number.

-h, --no-filename Suppress the filename prefix on output.

-o, --only-matching Show only the part of a line that matches.

-q, --quiet, --silent Suppress all normal output.

-r, -R, --recursive Search directories recursively.

-A NUM Print NUM lines of trailing context after matches.

-B NUM Print NUM lines of leading context before matches.

-C NUM Print NUM lines of context before and after matches.

-e PATTERN Use PATTERN for matching (useful for patterns starting with -).

--include=GLOB Search only files matching GLOB.

--exclude=GLOB Skip files matching GLOB.

--exclude-dir=DIR Skip directories matching DIR.

--help Display help and exit.

Examples

$ grep "TODO" src/*.js

Search for TODO in JavaScript files.

$ grep -rn "function" --include="*.ts" .

Recursively search for "function" in TypeScript files with line numbers.

$ grep -i "error" log.txt | head -5

Case-insensitive search for errors, showing first 5 matches.

$ grep -c "import" main.js

Count lines containing "import".

Notes

Operates on the SLICC virtual filesystem (LightningFS/IndexedDB). Also available as egrep (equivalent to grep -E) and fgrep (equivalent to grep -F). Glob patterns in file arguments are supported. Recursive search skips hidden files (those starting with .) by default.

See Also

rg, sed, awk, find