end row of the regular expression.\ \>: Ends with the row that matches the regular expression.[]: A single character. For example, [A] indicates that A meets the requirements.[-]: Range, such as [A-Z], that is, A, B, C Until Z all meet the requirements.. : All single characters.*: It can contain 0 characters.4. Run the grep command to use a simple instance.$ Grep 'test' d *Display all the lines containing
:\: Ignore the original meaning of special characters in regular expressions.^: Match the start line of the regular expression.$: Matches the end row of the regular expression.\ \>: Ends with the row that matches the regular expression.[]: A single character. For example, [A] indicates that A meets the requirements.[-]: Range, such as [A-Z], that is, A, B, C Until Z all meet the requirements.. : All single characters.*: It can contain 0 characters.
4. Run the
containing the know character and list the row number. Note that the case sensitivity is different.
[Root @ test/root] # grep-N 'know' regexp.txt
Example 2: find that the file contains the * character and list the row number:
[Root @ test/root] # grep-n' \ * 'regexp.txt
Example 3: I want to list all knows, regardless of Case sensitivity, and list the row numbers:
[Root @ test/root] #
1. Grep meaning:
Grep is combined by g/RE/p, where g indicates global, RE is short for regular expression, and p indicates print; that is, grep indicates "global search for regular expressions and print the row" (The grep name originated from the ex editor ).Grep works like
Common grep usageGrep Introduction
As described in the linux man file:
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 the matching lines. in addition, two variant programs
"retrieving a string in all files Maryls *~ |xargs rm-rfDelete all files ending with ~SVN filter svn folder1. Double-layer "filter" using a pipe, where the second grep uses the- voption, which isInverse MatchingTo print out rows that do not matchGrep-r 'function_name' * | grep-v '. SVN '2. Or more simply, use directly--exclude-diroption, which isSpecify exclusion directories, notice that the SVN front\.
matching test in the aa,bb,cc file.$ grep ' [a-z]/{5/} ' AA shows all lines that contain at least 5 consecutive lowercase characters for each string.$ Grep ' w/(es/) t.*/1 ' AA if West is matched, then es is stored in memory and labeled as 1 and then searches for any character (. *), followed by another ES (/1), and the line is displayed. If you use Egrep or
Grep, egrep, fgrep
Grep: searches for text based on the mode and displays the line of text matching the mode.
Summary:
1. Common grep Parameters
2. grep Regular Expression meta-character set (basic usage) and advanced usage
3. POSIX special character classes related to regu
'/(3/)/. [0-9].*/1 */1 '/etc/passwdNote: You can replace 3 for any other character you want
Output lines with words that contain at least 9 consecutive lowercase letters
$grep ' [a-z]/{9,/} '/etc/passwd
Outputs the file names under the current directory, which contain rows with such rows containing the ' SE ' string, ignoring the case.
$
], a meets the requirements.[-]: range, such as [A-z], i.e. A, B, C to Z all meet the requirements.。 : all the individual characters.*: There are characters, the length can be 0.4.grep command uses a simple instance $ grep ' test ' d* shows all the lines that contain test in a file that begins with D. $ grep ' test ' AA bb cc Displays the line that matches te
Text Search tool: Grep,egrep,fgrepgrep Introductiongrep: searches for text based on modal criteria and displays lines of text that conform to the pattern. Filter conditions: Text Word wildcards regular the expression of the meta-character combination to form a matching conditionA combination of the meta-characters of regular expressions and normal characters. That is pattern (pattern)
First, what is grep?Grep:global Search Regular expression (RE) and print out of the line, fully searching for regular expressions and printing them out, is a command-line tool that can find strings from text or streams, It can be more flexible by using regular expressions to find a string, that is, through complex patterns to find to meet your needs.Ii. Classification of regular expressions1. Basic Regular expression: BRE (basic REGULAR expression)2,
Grammar# grep Match_pattern filename//will output content that complies with the Match_pattern rules, match pattern is a wildcard character# grep-e Match_pattern filename//The match_pattern here is a regular expression# grep-o-e match_pattern filename//output only matching parts# grep-v Match_pattern filename//contains
lowercase letters followed by able strings, such as loveable,enable,disable, etc. ? matches 0 or more previous characters. such as: ' Gr?p ' matches the GR followed by one or no characters, then the line of P. A|b|c match A or B or C. such as: grep|sed matching grep or sed() grouping symbols, such as: Love (able|rs) ov+ match loveable or lovers, matching one or more ov. 6.Exampleparameter is not an exampl
displayed. If you use egrep or grep-E, you do not need to escape the "/" number and write it as 'W (ES) T. */1. Grep Regular Expression metacharacters (basic set)^For example, '^ grep' matches all rows starting with grep. $For example, '
protected] ~]# cat abc.txt |grep-q ' ee ' [[email protected] ~]# echo $?0 (input Instruction No results display, $?) the variable saves the most recent command exit status, resulting in 0 = correct) -A # Displays the key line and the down n rows[[email protected] ~]# cat abc.txt |grep-a1 ' ee ' dd ee FFAA Bb -B # Displays the line of keywords and the n rows up[[email protected] ~]# cat abc.txt |
2. grep commandgrep (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.2.1. General options and examples of GREP commandsgrep [OPTIONS] PATTERN [FILE ...]grep [OPTIONS] [-E PATTERN
First, Introductiongrep (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 works in such a way that it searches for a string template in one or more files. If the template includes
Well, here can not complain because of network reasons, several times to write blog is the speed of the good coax to back, Dan Hurt Ah!
Text Search tool: Grep,egrep,fgrep
1 (1) grep "^[[:alpha:]]*"/proc/meminfo(2)grep "^[a-za-z]\+"/proc/meminfo2 Grep-v
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.