1
0
Fork 0
mirror of https://github.com/tldr-pages/tldr.git synced 2025-04-29 23:24:55 +02:00
tldr/pages/common/grep.md

45 lines
963 B
Markdown
Raw Normal View History

2013-12-08 19:56:16 +11:00
# grep
> Matches patterns in input text.
> Supports simple patterns and regular expressions.
2013-12-08 19:56:16 +11:00
- Search for an exact string:
2015-10-22 15:31:52 +08:00
`grep {{something}} {{file_path}}`
2013-12-08 19:56:16 +11:00
- Search in case-insensitive mode:
2016-01-28 00:12:10 +02:00
`grep -i {{something}} {{path/to/file}}`
2016-01-28 00:12:10 +02:00
- Search recursively in current directory for an exact string:
`grep -r {{something}} .`
- Use a regular expression (`-E` for extended regex, supporting `?`, `+`, `{}`, `()` and `|`):
2013-12-08 19:56:16 +11:00
`grep -e {{^regex$}} {{path/to/file}}`
2013-12-08 19:56:16 +11:00
- Print 3 lines of context around each match:
2013-12-08 19:56:16 +11:00
`grep -C 3 {{something}} {{path/to/file}}`
2013-12-08 19:56:16 +11:00
- Print the count of matches instead of the matching text:
2013-12-08 19:56:16 +11:00
`grep -c {{something}} {{path/to/file}}`
2013-12-08 19:56:16 +11:00
- Print line number for each match:
2016-01-05 00:30:21 -05:00
`grep -n {{something}} {{path/to/file}}`
2016-01-05 00:30:21 -05:00
2016-06-21 15:11:27 +08:00
- Print file names with matches:
`grep -rl {{something}} .`
- Use the standard input instead of a file:
2013-12-08 19:56:16 +11:00
`cat {{path/to/file}} | grep {{something}}`
2014-07-27 10:23:56 +02:00
- Invert match for excluding specific strings:
2014-07-27 10:23:56 +02:00
2014-07-27 14:10:52 +02:00
`grep -v {{something}}`