Log in Go to the main page Page Discussion History Go to the file list Go to the site toolbox Bookmark and Share

Grep command

From RZWiki


Image:linux-logo-large.png

A command line program available on Linux platforms; used to used to search for regular expressions within files.

Contents

Image:Vm-power-on-medium.png Usage Syntax

grep [options] string [file/file_pattern...]

Common options include;

  • -r or -R - read files recursively
  • -A nn - display the specified nn number of lines after each match
  • -B nn - display the specified nn number of lines before each match
  • -C nn - context: display the specified nn number of lines before and after each match
  • -c - count: display a count of lines containing the specified string
  • --colour - colour the matching string in any output
  • -E - interpret the specified string as an extended regular expression
  • -f - obtain search strings from the specified file
  • -H - prefix each line of output with the file name the match was found in
  • -i - ignore case in both the specified string and file
  • -n - prefix each line of output with the line number of the match in the file

Image:Vm-power-on-medium.png Usage Examples

grep -R -C 5 power.png * - search for the string power.png in all files (*) in the present working directory and any subdirectories (-R) and display 5 lines of text before and after each match (-C 5)

Image:accessories-text-editor-v2-medium.png Usage Notes

string can include regular expressions

Image:accessories-text-editor-v2-medium.png Linux Usage Notes

With most Linux or Unix commands;

  • Non root users may need to prefix commands with the sudo command, for example: sudo chmod 644 *
  • Brief help can be displayed using the -h or --help parameter, for example: chmod --help
  • A full command manual can be displayed using the man command followed by the command name, for example: man chmod
  • Sometimes 'info' pages are used instead of or to provide more information than man pages; for example: info chmod
  • Version information can normally be display using the -v, -V or --version parameter, for example: chmod --version. However, this paramater is also frequently used to display verbose output.

noinclude/noinclude

Image:icemon-medium.png Related Commands

Use the zgrep command to search for regular expressions within files compressed with the compress or gzip commands.

Use the zipgrep command to search for regular expressions within ZIP compressed files.

Image:object-flip-horizontal-medium.png Command Equivalents

The Cisco command equivalent is the Image:Cisco-logo-small.png

The Extreme command equivalent is the Image:Extreme-logo-small.png

The Linux command equivalent is the Image:linux-logo-small.png

The F5 BigIP command equivalent is the Image:F5-logo-small.png

The Blue Coat SGOS command equivalent is the

The XXX platform command equivalent has the same name:

The closest Nokia IPSO command equivalent is the

Image:icemon-medium.png Related Articles

Information on Cisco commands Image:Cisco-logo-small.png

Information on Vyatta commands Image:Vyatta-logo-small.png

Information on Extreme commands Image:Extreme-logo-small.png

Information on Linux commands Image:Tux-small.png

Information on F5 BigIP commands Image:F5-logo-small.png

Information on Blue Coat SGOS commands

Information on Nokia IPSO commands


Image:internet-group-chat-small.png We really do appreciate all feedback so please do send your comments, suggestions or corrections to sjiveson#routerzone.eu
(replacing the # with an @)


Site Toolbox:

Personal tools
This page was last modified on 22 December 2009, at 17:47. - This page has been accessed 38 times. - Disclaimers - About RZWiki
Powered by MediaWiki