H I O X INDIA
LINUX Commands
 HOME  ||  Scripts  ||  Purchase  ||  Tutorials  ||  Images  ||  Tools  ||  Templates 
  :-)  Send Page   :-)   Feedback   :-)   Register   :-)   Links   :-)   Support   :-)
Español Français 中文 Deutsch
 Forums   Hosting   Internet Stats   Easy Calculation   FUN Games 

LINUX / UNIX cmd
Introduction
Commands in A
Commands in B
Commands in C
Commands in D
Commands in E
Commands in F
Commands in G
Commands in H
Commands in I
Commands in J
Commands in K
Commands in L
Commands in M
Commands in N
Commands in P
Commands in R
Commands in S
Commands in T
Commands in U
Commands in W
Commands in Y
More about Linux
Feedback




grep Linux Commands


Topic

What is Linux grep Command?




Explanation

grep COMMAND:
     grep command selects and prints the lines from a file which matches a given string or pattern.

SYNTAX:
  The Syntax is
     grep [options] pattern [file]

OPTIONS:
     
-A Print num lines of text that occur after the matching line.
-a Don't suppress output lines with binary data, treat as text.
-b Print the byte offset of input file before each line of output.
-c Print's the count of line matched.
-d action Define action for accessing the directories
read  read all files in the directories.
skip  skip directories.
recurse  recursively read all files and directories
-e pattern Search for pattern.
-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
Purchase scripts from us
A webmaster/web master resource website
  1. To print all lines containing hscripts :
    grep 'hscripts' 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

  2. To print the count of line that matches hscripts.
    grep -c 'hscripts' file1.txt
    The output will be.
    3

  3. To print the lines that starts as hscripts.
    grep '^hscripts' file1.txt
    The output will be.
    hscripts has many valuable free scripts
    hscripts include free tutorials and free gif images

  4. To Search the files in HEC directory which has the string "include":
    grep -c 'include' HEC/*
    The above command will print the file name and count of line that matched the string "include"
    Sample output:
    HEC/admin.php:3
    HEC/auth.php:1
    HEC/calendar.php:3
    HEC/checklogin.php:0
    HEC/colors.php:0
    HEC/msize.php:3





        Find LINUX Commands... Hope you enjoy this tutorial. We welcome your Valuable feedbacks or suggestions on this LINUX / UNIX cmd reference. This is a copyright content.


privacy policy     license     sitemap
© 2004-2009 HIOX INDIA - hioxindia.com

Other Links