Bash 5 reference · Text and System Tools
grep (Linux command)
Search files or input for lines matching a pattern, with options for case, counts, context, recursion and regex.
Bash 5
Syntax
grep [OPTIONS] PATTERN [FILE...]
Parameters
| Parameter | Description |
|---|---|
-i |
Ignore case. |
-v |
Invert the match. |
-n / -c |
Line numbers / count. |
-r / -l |
Recursive / list file names. |
-E |
Extended regex. |
-o |
Print only the matched part. |
-q |
Quiet: just the exit status. |
Examples
printf 'INFO up\nERROR db\nerror cache\n' > app.log
grep -in error app.log
grep -c -v -i error app.log
Output
2:ERROR db 3:error cache 1
Run this on your computer — see “Get Started” for setup.
echo 'order=42 total=19.99 order=7' | grep -oE 'order=[0-9]+'
Output
order=42 order=7
Run this on your computer — see “Get Started” for setup.
Related
sed· Edit text streams: substitute with s/old/new/, delete or print lines by number or pattern, and edit files in place.awk· Process text by fields: print and filter columns, compute sums and group totals, with a small built-in language.- Bash grep: Search Text · tutorial