egrep Linux Commands

What is Linux egrep Command?

Explanation

egrep COMMAND:

egrep command is used to search and find one or more files for lines that match the given string or word.

SYNTAX :


egrep [options] pattern [file]

OPTIONS:


-b Print the byte offset of input file before each line of output.
-c Print's the count of line matched.
-epattern list Searches the pattern list.
-h Print matched lines but not filenames.
-i Ignore changes in case; consider upper- and lower-case letters equivalent.
-n Print line and line number.
-q Prints in quite mode, prints nothing.
-r Recursively read all files in directories and in subdirectories found.
-v Prints all the lines that do not match.
-V Print Version.
-w Match on whole word only.
You can also use Patterns for search operation.
. Matches single character.
* Wild Character.
^ Starting with.
$ Ending with.

EXAMPLE:


Lets assume that we have a file file1.txt and it has the following data.
hscripts has many valuable free scripts
It is the parent site of www.forums.hscripts.com
hscripts include free tutorials and free gif images
free DNS lookup tool
Purchase scripts from us
A webmaster/web master resource website
  1. To search more words from a file :
    egrep'hscripts|forums|free'file1.txt
    The output will be.
    hscripts has many valuable free scripts
    It is the parent site of www.forums.hscripts.com
    hscripts include free tutorials and free gif images
    free DNS lookup tool

  2. To print the lines containing "free" followed by images:
    egrep'free.*images'file1.txt
    The output will be.
    hscripts include free tutorials and free gif images

Ask Questions

Ask Question