Wednesday, March 4, 2015

Regular Expression

Command                                                       Function
grep this demo                            Lists the lines that contains the string this
grep 'end of' demo                      Quotes mandatory for text containing space
grep this demo*                          Search this in multiple files
grep –c to demo                             Number of occurrence of the word to in the file
grep –n sequence demo                   Display line numbers along with matching lines
grep –v word demo                     Displays lines that does not contain the text word
grep –l vim *                               Displays files containing text vim
grep –i WORD demo                  Search for text ignoring case differences
grep '^[0-9]' demo                     Lines that start with a number
grep '[0-9]$' demo                     Lines that end with a number
ls -l | grep "^d"                      Display the subdirectory names
grep –c "^$" demo                   Display count of blank lines in the file.
grep "2....$" stud                      Display lines that ends in the range 20000–29999
egrep "lower|UPPER" demo         Display lines that match either lower or upper
egrep "(previous|current)
word" demo                              Display lines that match either previous word or current word

No comments:

Post a Comment