grep insensitive or case sensitive

Grep is a command line utility used in Unix, Linux, Solaris, Mac OS and even in Windows to search particular patterns in a file.
This utility is widely used for multiple purposes like I use it to find text in my too large production log files.
The grep command is used to search one file or multiple files for lines that contains a pattern. The grep command is case sensitive by default

The syntax for the grep command is:

1
grep [options] pattern [files]

options:

-b Display the block number at the beginning of each line.
-c Display the number of matched lines.
-h Display the matched lines, but do not display the file names.
-i Ignore case sensitivity.
-l Display the filenames, but do not display the matched lines.
-n Display the matched lines and their line numbers.
-s Silent mode.
-v Display all lines that do NOT match.
-w Match whole word.

Examples:

1
grep -c 'Rizvi' mylogs.log

will return the count of lines containing ‘Rizvi’ in mylogs.log
grep search that ignores case, or is case insensitive, use the -i option.

1
grep -i 'Syed Saulat Hussain Rizvi' mylogs.log

will return the lines containing case in-sensitive ‘Syed Saulat Hussain Rizvi’ in mylogs.log

 

1
grep 'Syed Saulat*' mylogs.log

we can also use wild cards

 

You can also use grep in conjunction with tail command, it greatly helps you viewing a running system log e.g.

1
 tail -f  mylog.log | grep 'INFO'

it will return all the upcoming lines having the keyword INFO

 

 

 

2 Responses to “grep insensitive or case sensitive”

  1. Adnan Siddiqi Says:

    AOA Saulat Bhai

    Quite lush blog and pretty cool information. Keep it up!

  2. Greetings! I know this is kinda off topic nevertheless I’d figured I’d ask.
    Would you be interested in exchanging links or maybe guest
    writing a blog article or vice-versa? My blog goes over a
    lot of the same subjects as yours and I think we could greatly benefit from each
    other. If you might be interested feel free to send me an email.
    I look forward to hearing from you! Superb blog by the way!

Leave a Reply

Spam Protection by WP-SpamFree

Einfobuzz Site Map