Search Text File In UNIX

To search for text in a file on UNIX, you can use the grep command. grep is a command-line utility that searches for patterns in files. Here’s how to use it:

  1. Open a terminal on your UNIX system.
  2. Navigate to the directory where the file is located using the cd command.
  3. Type grep followed by the search term or pattern you want to search for, and then the filename. For example, if you want to search for the word “example” in a file called myfile.txt, you would type:
grep example myfile.txt
  1. Hit Enter to execute the command. grep will search the file and output any lines that contain the search term.

If you want to search for a pattern in all files in a directory, you can use the following command:

grep pattern *

The * symbol is a wildcard that matches all files in the current directory. This command will search all files and output any lines that contain the pattern you specified. (Tramadol)

Leave a Comment