How To Find Text In a File In Linux

In this article I will show how to find text in a file in Linux using grep command.

Grep searches for patterns in each file. Patterns is one or patterns separated by newline characters, and grep prints each line that matches a pattern.

$ grep -rw PATH -e PATTERN

Where is:

-r is recursive

-w only matches the whole words

PATH where search

-e pattern

PATTERN what you serach

-i ignore case

Find Text in File Example

For example, we want to find in which file there is a text12.34.56.78.

Run:

$ grep -rw /etc/ -e 12.34.56.78

Output:

/etc/text_file.txt:IP: 12.34.56.78

So grep found the file with name /etc/text_file.txt

Conclusion

You just learn how to find text in a file in Linux using grep command.

Grep is a powerful tool with many features. Тo learn more about the grep command, read the official documentation on grep man pages.

Discuss article in ArsTech Forum

   

If you like what you are reading, please:

Buy me a coffeeBuy me a coffee

arstech

Leave a Reply