Forrest logo
back to the fgrep tool

fgrep:tldr:44066

fgrep: Count the number of lines that match the given string in a file.
$ fgrep -c ${search_string} ${filename}
try on your machine

The command "fgrep -c ${search_string} ${filename}" is used to search for a specific string in a file and count the number of occurrences of that string.

Here is a breakdown of the command:

  • "fgrep" stands for "fixed grep" and is a command-line tool used for searching patterns in text files.
  • "-c" option is used to count the number of lines that contain the searched string in the file.
  • "${search_string}" refers to the string you want to search for in the file. It should be replaced with the actual string you want to search for.
  • "${filename}" refers to the name of the file in which you want to search for the string. It should be replaced with the actual file name you are working with.

So, when you run the command with the appropriate values for "${search_string}" and "${filename}", it will search for the given string in the specified file and return the count of the number of lines that contain the searched string.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the fgrep tool