Grep command

From Linux Shell Scripting Tutorial - A Beginner's handbook
Jump to: navigation, search

The grep command searches the given input files for lines containing a match to the given PATTERN. By default, grep prints the matching lines. It has no limits on input line length other than available memory, and it can match arbitrary characters within a line.

grep Syntax

The general syntax is as follows:

grep Options Search-Pattern InputFileNames

Example

In this example, you are printing the version number of grep command:

grep -V

OR

grep --version

Sample outputs:

GNU grep 2.5.4

Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

External links