grep – Linux search text in the file

To find a string in a text file on your Linux system/server, we can use the grep command.

For example, you are looking for certain strings like “generate” and “host” in the file /etc/hosts

To search text generate run the below command,

cat /etc/hosts | grep -i generate

To search text host run the below command, as the host string is at multiple locations, the result will display all occurrences of string host in file /etc/hosts

cat /etc/hosts | grep -i host