Forrest logo
back to the egrep tool

egrep:tldr:1cf55

egrep: Print file name and line number for each match.
$ egrep --with-filename --line-number "${search_pattern}" ${filename}
try on your machine

The command egrep --with-filename --line-number "${search_pattern}" ${filename} is used to search for a specific pattern in a file or multiple files using extended regular expressions.

Here is an explanation of each component of the command:

  • egrep: This command is used for pattern matching using extended regular expressions. It searches for lines matching a specified pattern and prints them to the output.

  • --with-filename: This option prints the matching lines along with the corresponding filenames where the pattern was found.

  • --line-number: This option prints the line numbers of the matching lines.

  • "${search_pattern}": This is the pattern or regular expression that you want to search for. It could be a simple word or a complex regular expression.

  • ${filename}: This is the name of the file or files in which you want to search for the pattern. It can be a single file or multiple files separated by spaces.

When you run this command, it will search for the specified pattern in the given file(s) and print the matching lines along with the filenames and line numbers.

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 egrep tool