The use of grep

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

Command options

-?


At the same time display matching rows up and down? For, such as: grep -2 pattern filename display at the same time matching row on row 2.


-a, --text


Equivalent to match text, for (Binary file (standard input) matches) error


-b, --byte-offset


Print matching block number print the line in front of the.


-c,--count


Print only match the number of rows, does not display the matching content.


-f File, --file=File


Extraction of the template from the file. Empty file contains 0 templates, so it doesn't match anything.


-h, --no-filename


When searching for multiple files, do not display the matching file name prefix.


-i, --ignore-case


Ignorecase difference.


-q, --quiet


Canceling the show, only returns an exit status. 0 then said to find matching rows.


-l, --files-with-matches


Print matching template file list.


-L, --files-without-match


The print does not match the template file list.


-n, --line-number


In the matching row in front to print line numbers.


-s, --silent


Do not display information about the error does not exist or cannot read file.


-v, --revert-match


Retrieve, display only the rows that do not match.


-w, --word-regexp


If \<and \> reference, the expression as a word search.


-R, -r, --recursive


All file directory recursive under, including subdirectories. For example, grep -R'pattern'test all files in test and its subdirectories, matching pattern.


-V, --version


Software version information.


Expression of symbol set

^

To begin to anchor line such as:'^grep'matching all the lines starting with grep.

$

The anchor end of the line:'grep$'matching all the grep at the end of the line.

.

Matching a non newline characters such as:'gr.p'matching GR followed by an arbitrary character, then p.

*

Matches zero or more of the previous characters such as: '*grep' (note * space before) to match all zero or more spaces followed by grep lines, need to use egrep or grep with the -E option. Together with the representatives of any character.

[]

Matching a specified range of characters, such as'[Gg]rep'Grep and grep.

[^]

Matching a outside the specified range of characters, such as:'[^A-FH-Z]rep'match the first does not contain A-F and H-Z a letter, followed by rep lines.

\(..\)

Tag matching character, such as' \ (love\) ', love is labeled as 1.

\<

To start, the anchoring of words such as:'\<grep'matching contains words starting with grep line.

\>

End, the anchoring of words such as'grep\> 'match contains the grep at the end of the word.

x\{m\}

Repeat the characters x, m, such as:'o\{5\}'matching contains 5 o.

x\{m,\}

The repeated character x, at least m times, such as:'o\{5, \}'matching at least 5 o.

x\{m,n\}

The repeated character x, at least not more than m times, n times, such as:'o\{5,10\}'5--10 o.

\w

Matching text and numeric characters, namely [A-Za-z0-9], such as:'G\w*p'matching with G followed by zero or more characters or digits, then p.

\W

\The form of the W, match one or more non word characters, such as punctuation period etc.

\b

The word locking character, such as:'\bgrep\b'only matching grep. [1]

For the element egrep and grep -E extended character set

+

Match one or more previous character. Such as:'[a-z]+able', match one or more lower case letter followed by a string of able, such as loveable, enable, disable etc.

?

Matches zero or a previous character. Such as:'gr? P'matching GR is followed by a character or not, then p lines.

a|b|c

Match a or B or C. Such as: grep|sed grep or sed

()

Grouping symbols, such as: Love (able|rs) ov+ loveable or lovers, to match one or more ov.

x{m},x{m,},x{m,n}

Interaction with x\{m\},x\{m,\},x\{m,n\}


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Tobias at November 10, 2013 - 10:04 AM