Sunday, May 12, 2013

grep (Global Regular Expression Parser) Command in Unix

  • Search file(s) for specific text. 
  • By default, grep displays the matching lines. 
  • Search pattern allows regular expression
Syntax : $grep [options] [find pattern] [filename]

Options Descriptions
-v Print all lines that dont match pattern
-n Print the matched line and its line number
-l Print only the names of files with matching lines
-c Print only the count of matching lines
-i Match either upper or lowercase
-w Print the lines which is matched exact given word
-r Recursive search folder and sub-folder
Example:

file name : sample.dat

applas11i13
sunday is holiday
monday
tuesday
wednesday
thursday
friday
saturday
Sunday SUCCESS
SUNDAY 1234
SUUNDAY
this


$ grep "Sunday" sample.dat
Sunday SUCCESS

This is used to find the line in which the word ‘Sunday’ in a file ‘sample.dat’ occurs  . This is also case sensitive.

$ grep -i "Sunday" sample.dat
sunday is holiday
Sunday SUCCESS
SUNDAY 1234

This is used to find the line in which the word ‘Sunday’ in a file ’sample.dat’ occurs. This is ignoring the case sensitive.

$ grep -v "Sunday" sample.dat
applas11i13
sunday is holiday
monday
tuesday
wednesday
thursday
friday
saturday
SUNDAY 1234
SUUNDAY
this

This is used to find all the line except the word ‘Sunday’  in a file ‘sample.dat’. This is also case sensitive.

$ grep -iv "Sunday" sample.dat
applas11i13
monday
tuesday
wednesday
thursday
friday
saturday
SUUNDAY
this

  This is used to find all the line except the word ‘Sunday’ in a file ‘sample.dat’. This is ignoring case sensitive.

$ grep -w "is" sample.dat
sunday is holiday

           This is used to find the line in which the word ‘is’ occurs  in a file ‘sample.dat’. This is also case sensitive.

$ grep  "is" sample.dat
sunday is holiday
this 

       This is used to find the line in which  the  word ‘is’ occurs in a file ‘sample.dat’. This is also case sensitive.



No comments:

Post a Comment

Price List Query for Item

 SELECT qph.list_header_id,        qph.name,        qph.description,        qphh.start_date_active,        qphh.currency_code,        q...