tldr/pages/common/fgrep.md

30 lines
808 B
Markdown
Raw Normal View History

2020-04-23 20:18:23 +01:00
# fgrep
> Matches patterns in files.
> Supports simple patterns and regular expressions.
2021-04-17 16:15:37 +01:00
> More information: <https://manned.org/fgrep>.
2020-04-23 20:18:23 +01:00
- Search for an exact string in a file:
`fgrep {{search_string}} {{path/to/file}}`
- Search only lines that match entirely in files:
`fgrep -x {{path/to/file1}} {{path/to/file2}}`
- Count the number of lines that match the given string in a file:
`fgrep -c {{search_string}} {{path/to/file}}`
- Show the line number in the file along with the line matched:
`fgrep -n {{search_string}} {{path/to/file}}`
- Display all lines except those that contain the given regular expression:
`fgrep -v {{^regex$}} {{path/to/file}}`
2020-12-04 12:37:44 +00:00
- Display filenames whose content matches the regular expression at least once:
2020-04-23 20:18:23 +01:00
`fgrep -l {{^regex$}} {{path/to/file1}} {{path/to/file2}}`