CentOS Linux Server Guide

Finding character strings in CentOS Linux

grep command is used to search or given character in files.

 

Command and Options:

grep  [options] pattern filename(s)

 

 

Option:

 
Options   Description
-n display lines together with oine number
-c display only total number of lines that matched the pattern
-i ignore case distinctions in both the pattern and the input files
-v display all lines that don't match the given pattern
-f filename take list of patterns from a file, one line per time
-C display leading lines before and trailing and trailing text after matching lines

 

Examples:

 

The following example "fail" string in error.log. If matched, it will output all matched line to screen
grep fail error.log

 

The following example,will display 2 lines of leading and trailing context arounf the matched lines
grep -C2 james namelist.txt

 

The following example will display total count of matched lines
grep -c james namelist.txt

 

Back to Managing Files and Folders in CentOS Linux

 



Copyright 2011 http://www.1a-centosserver.com All Rights Reserved

All trademarks are the property of their respective owners.

Contact Us | Terms of Use | Privacy Policy