Archive for the ‘Linux’ Category

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

 

 

 

Einfobuzz Site Map