To search for a specific text pattern in a file using Bash, you can use the grep
command. Here are the steps:
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.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".