2013-12-08 08:56:16 +00:00
|
|
|
# grep
|
|
|
|
|
2016-01-07 17:31:27 +00:00
|
|
|
> Matches patterns in input text.
|
|
|
|
> Supports simple patterns and regular expressions.
|
2013-12-08 08:56:16 +00:00
|
|
|
|
2016-01-07 17:31:27 +00:00
|
|
|
- Search for an exact string:
|
2015-10-22 08:31:52 +01:00
|
|
|
|
2013-12-09 11:12:16 +00:00
|
|
|
`grep {{something}} {{file_path}}`
|
2013-12-08 08:56:16 +00:00
|
|
|
|
2016-01-27 22:12:10 +00:00
|
|
|
- Search without case-sensitivity:
|
|
|
|
|
|
|
|
`grep -i {{something}} {{file_path}}`
|
|
|
|
|
2016-01-07 17:31:27 +00:00
|
|
|
- Search recursively in current directory for an exact string:
|
2014-01-28 12:41:32 +00:00
|
|
|
|
|
|
|
`grep -r {{something}} .`
|
|
|
|
|
2016-01-07 17:31:27 +00:00
|
|
|
- Use a regex:
|
2013-12-08 08:56:16 +00:00
|
|
|
|
2013-12-09 11:12:16 +00:00
|
|
|
`grep -e {{^regex$}} {{file_path}}`
|
2013-12-08 08:56:16 +00:00
|
|
|
|
2016-01-07 17:31:27 +00:00
|
|
|
- See 3 lines of context:
|
2013-12-08 08:56:16 +00:00
|
|
|
|
2013-12-09 11:12:16 +00:00
|
|
|
`grep -C 3 {{something}} {{file_path}}`
|
2013-12-08 08:56:16 +00:00
|
|
|
|
2016-01-07 17:31:27 +00:00
|
|
|
- Print the count of matches instead of the matching text:
|
2013-12-08 08:56:16 +00:00
|
|
|
|
2013-12-09 11:12:16 +00:00
|
|
|
`grep -c {{something}} {{file_path}}`
|
2013-12-08 08:56:16 +00:00
|
|
|
|
2016-01-07 17:31:27 +00:00
|
|
|
- Print line number for each match:
|
2016-01-05 05:30:21 +00:00
|
|
|
|
|
|
|
`grep -n {{something}} {{file_path}}`
|
|
|
|
|
2016-01-07 17:31:27 +00:00
|
|
|
- Use the standard input instead of a file:
|
2013-12-08 08:56:16 +00:00
|
|
|
|
2013-12-09 11:12:16 +00:00
|
|
|
`cat {{file_path}} | grep {{something}}`
|
2014-07-27 09:23:56 +01:00
|
|
|
|
2016-01-07 17:31:27 +00:00
|
|
|
- Invert match for excluding specific strings:
|
2014-07-27 09:23:56 +01:00
|
|
|
|
2014-07-27 13:10:52 +01:00
|
|
|
`grep -v {{something}}`
|