Search Text File In UNIX

www.la‮ttu‬uri.com
Search Text File In UNIX

To search for a specific string or pattern in a text file in Unix, you can use the grep command.

Here is an example of how to use the grep command to search for a string in a text file:

grep 'string' file.txt

This command searches for the specified string in the file.txt text file and prints any lines that contain the string.

You can also use the -i option to ignore case when searching, the -n option to print the line numbers of the matching lines, and the -r option to search recursively through directories.

For example, to search for the string hello in all .txt files in the /path/to/search directory and its subdirectories, ignoring case and printing the line numbers of the matching lines, you can use the following command:

grep -inr 'hello' /path/to/search/*.txt

By using the grep command, you can search for a specific string or pattern in a text file in Unix. It's always a good idea to carefully review the documentation and use the appropriate options and syntax when working with grep. This will help ensure that your search is accurate and efficient.

Created Time:2017-10-30 14:27:17  Author:lautturi