tldr/pages/common/fgrep.md

30 lines
828 B
Markdown
Raw Normal View History

2020-04-23 20:18:23 +01:00
# fgrep
> Matches fixed strings in files.
> Equivalent to `grep -F`.
> More information: <https://www.gnu.org/software/grep/manual/grep.html>.
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 {{search_string}} {{path/to/file1}} {{path/to/file2}}`
2020-04-23 20:18:23 +01:00
- 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 search string:
2020-04-23 20:18:23 +01:00
`fgrep -v {{search_string}} {{path/to/file}}`
2020-04-23 20:18:23 +01:00
- Display filenames whose content matches the search string at least once:
2020-04-23 20:18:23 +01:00
`fgrep -l {{search_string}} {{path/to/file1}} {{path/to/file2}}`