grep (Global Regular expression version) allows schema lookup of text files, and grep supports basic regular expressions and its extension sets.
GREP has three kinds of variants:
grep standard grep command
Egrep extends the
Note: Some modifications have been made on the basis of the original article.
Grep command introduction:
In the ex Editor (I have never used it), when you start the ex editor and want to find a string, type::/Pattern/P
:/G/pattern/P
This is why grep is called. P indicates print, and when G appears before pattern, it indicates "all rows in the file" or "perform global replacement ".
The pattern to be search
not" can do "but" you Should.3 life was not easy for any of Us.4 We mu St Work hard.123456785 We hope so we can see you soon6"Examples of common usage"1. Exclude specified content[e-mail protected] test]# grep-v We file The world are not a can do, but you Should.3 life is isn't easy for any of us. 5 We hope that we can see you soon62. Count the number of times we appear[[email protected] test]# grep-c We f
(shell wildcard symbol matches any character of any length) . * Match any character any time\? Match its preceding character 1 or 0 times \{m,n\} matches the characters preceding it at least m times, up to N times Location Anchoring: ^ Anchor Line, any content after the second character must appear at the beginning of the line $ anchor Line end, any content in front of the second character must appear at the end of the row ^$ Blank line \ \> or \b anchors the ending, any character preceding it
Introductiongrep (Global search Regular expression (RE) and print out of the line, full search of regular expressions and print out rows) is a powerful text search tool that uses regular expressions to search for text . and print out the matching lines.The grep family of Unix includes grep, Egrep, and Fgrep. Egrep and
the way they are supported is slightly different. Regular expressions are divided into basic regular expressions and extended regular expressions, different extended positive expressions support a little more,grep supports basic regular expressions,egrep (GREP-E) supports extended regular expressions, and fgrep Regular expressions are not supported. Basic Regula
One, grep (abbreviated from globally search a Regular expression and print) is a powerful text-search tool that can use regular expressions to search for text and print matching lines. The grep family of Unix includes grep, egrep, and Fgrep
grep: The default suppor
The grep command in a Linux system is a powerful text search tool that uses regular expressions to search for text and print the rows that match.The full name of grep is: Global Search Regular Expression and print out the Line.grep works by searching for a string pattern in one or more files, if the template includes spaces, it must be referenced, all strings after the template are treated as filenames, and
description:First introduce the basic use of grep:grep [OPTIONS] pattern[file ...][OPTIONS]--color=auto/always/never: Displays matching strings in color (very useful features, captured strings with color display.) )-O: Show only the matching string-I: Ignore case-V: Show rows that cannot be matched by a pattern-E: Using extended regular expressions, you can also use egrep instead of GREP-E-A #: matching li
Grep command output displays highlighted characters
After the grep command is executed, the "-- color = auto" parameter can be added to the output color of the terminal.
The other two methods are as follows:
1. Set environment variables:
Export GREP_OPTIONS = "-- color = auto"
2. Modify. bashrc
Alias grep and set it with alias. My system has been written but comm
information that matches the filter.
Grep executes the regular expression in the format of grep "keyword" file
Grep is a command used to execute basic regular expressions. It cannot recognize metacharacters in extended regular expressions.
Grep-E = egrep is used to execute
Tag: The grep command of the Shell scripting toolgrep (abbreviated from globally search a Regular expression and Print) is a powerful text-search tool for Linux systems that can search for text using regular expressions , and print out the matching lines. Egrep and Fgrep are grep extensions that support more re- metacharacters ,fgrep is fixed
filter directories with matching characters-N Displays the line number of the row that matches the character-E Switch to Egrep-Q only as a judgment without outputting results--color Highlighting matching charactersgrep ' root '/etc/passwd Filter out rows with root Root:x:0:0:root:/root:/bin/bashoperator:x:11:0:operator:/root:/sbin/nologingrep-v ' root '/etc/passwd Filter out rows with no root bin:x:1:1:bin:/bin:/sbin/nologindaemon:x:2:2:da
The need for text lookup:
Grep,egrep,fgrep
grep: Searches the text according to the pattern, and displays the line of conformance to the pattern,
Pattern: A matching condition in which a literal character wildcards expressions a combination of the metacharacters of an expression
Format: grep [option] Pattern file ...
-
using the grep ' word1|word2 ' filename is not the right command.
You should use the following command:
1,grep-e ' word1|word2 ' filename2,egrep ' word1|word2 ' filename3,grep ' word1/|word2 ' filenameWhy do I need to add-e, about grep and
-without-match
Print the list of files that do not match the template.
-N, -- line-Number
Print the row number before the matched row.
-S, -- silent
The error message about the nonexistent or unreadable file is not displayed.
-V, -- revert-match
Reverse search: Only unmatched rows are displayed.
-W, -- word-Regexp
If it is referenced by/
-V, -- version
Displays the software version information.
6. Instance
To make good use of the gre
Man grep
Grep searches the named input files (or standard input if no files are named, or if a single hyphen-minus (-) is given as file name) for lines containing a match to the given pattern. by default, grep prints thematching lines.
In addition, three variant programs egrep, fgrep and rgrep areavailable.
the options of the command and the corresponding adjustable parameters in the system kernel.
Instance: view the common file format in the current directory
lc@lc-Lenovo:~/work/test$ lsdir1 dir2 main.clc@lc-Lenovo:~/work/test$ find . -type f -print |xargs file./main.c: C source, ASCII text./dir1/main.c: emptylc@lc-Lenovo:~/work/test$
Ii. grep command: comprehensively search for regular expressions and output the results.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.