Search pattern using grep command in Linux

You can search word in file using grep command in Linux.

grep [options] <pattern> <file(s)>

Examples with different options:
1. grep anil file1
2. To search exact word in file
      grep -w ‘anil’ file2
3. To search words in multiple files or in directory
      grep -r ‘anil’ /tmp
4. Case insensitive search
      grep -i “Anil’ file3

Note: If you want to discard errors during above commands execution, then redirect errors in /dev/null using below command [/dev/null is the device where anything you send simply disappears].

grep -w ‘anil’ /tmp/ 2> /dev/null

You may want to see
How to use crontab in Linux

Cron is the system process that will automatically perform tasks for you according to a set schedule. The schedule is Read more

How to extract archive file in Linux

To extract archive file in Linux, you can use the tar command, used for extracting content from the archive files. "tar" Read more

How to Change permission of a file in Linux

chmod command is used to change the permission of a file in Linux. In Linux, there is a set of rules for Read more

How to create and remove the directory in Linux

There is a separate command to create and remove the directory in Linux. mkdir command is used to create a directory/folder Read more

Leave a Reply

Your email address will not be published. Required fields are marked *