How to search for a specific text pattern in a file using Bash?

To search for a specific text pattern in a file using Bash, you can use the grep command. Here are the steps:

  1. Open your terminal or command prompt.
  2. Use the following syntax to search for a specific pattern in a file: grep "pattern" file.txt Replace "pattern" with the text pattern you want to search for, and file.txt with the name of the file you want to search in.
  3. Hit Enter to execute the command.
  4. The grep command will search for the specified pattern in the file and display any matching lines.

For example, let's say you want to search for the word "example" in a file named sample.txt. You can run the following command:

grep "example" sample.txt

This will display any lines in the sample.txt file that contain the word "example".