Search pattern using grep command in Linux

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

Syntax:
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 sort contents of a file

The sort command is used to sort the contents of a file. You can sort the data in a text Read more

How to use sed command in Linux

sed, short for "stream editor", allows you to filter and transform text. A stream editor is used to perform basic Read more

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

Leave a Reply

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