wordGroup\ (string\): string as a set of characters, a whole, for a back referenceBack to reference\1: Refers to the first opening parenthesis and all the contents of the corresponding closing parenthesis\2\3grep Basic usage:grep [OPTIONS] PATTERN [FILE ...]OPTIONS-I: Ignore case--color: descriptor color of the searched word-V: Show rows that are not matched by the pattern-O: Displays only the string that is matched to-A #: Indicates the line to which grep
Text processing on Linux "threesome"grep, Egrep, Fgrep: Text Search tool; Search operations on a given text based on "pattern";Regular Expressions: Regular expression, REGEX, a pattern written by a class of special characters and text characters, some of which do not represent their literal meaning, but are used to denote the function of control or distribution;Divided into two categories:Basic Regular Expr
/wKioL1RyBW6gyoowAAENihiIgQE185.jpg "alt=" Wkiol1rybw6gyoowaaenihiigqe185.jpg "/>5. Find one or two digits in the/etc/passwd file;650) this.width=650; "title=" QQ picture 20141123222739.png "style=" Float:none; "src=" http://s3.51cto.com/wyfs02/M01/53/D7 /wkiom1rybplhrb48aamxu-qfgas665.jpg "alt=" Wkiom1rybplhrb48aamxu-qfgas665.jpg "/>6, displays the line that starts with at least one whitespace character in/boot/grub/grub.conf;650) this.width=650; "Width=" 857 "height=" 131 "title=" QQ picture 2
that each row has a tab (unspace) character on the left and right of 11, so you can use the regular expression "tab (unspace) 11tab (unspace)" for exact search.
However, if you use the command cat delete. log | grep '\ t11 \ t' | wc or cat delete. log | grep '\ t11 \ t' | one wc cannot be found.
In fact, there are two ways to correctly match the tab character in li
The main post to be deleted must be counted in the log file, and the log file is separated by tab characters. Assume that the log file name is delete. log.
Save the format and save the data as follows,
Delete date post type (11 as the main post, 12 as the reply) Post id operator id
12 71163578 1153089
11 71163800 134379
12 71163801 134379
11 71151662 2064561
2011-11-01 00:42 11 71163897 719476
11 71164159 2215597
12 71164712 2317663
12 71164820 111
12 71164841 622530
12 71164881 1999836
11 71
grep is used to find strings
Case 1: Get the user's home directory
For example, if you have a user named Whuang, how do I get his home directory?grep"^whuang:" /etc/passwd |awk -F : {‘print $6‘}
Case 2: Get the user's ID
grep"^whuang:" /etc/passwd |awk -F : {‘print $3‘}
Case 3: Get the ID of the owning group
Whereis Find the installation path for the software-B finds only binary files-M only find help files-S find source code only-U excludes the specified type file-F Show file name only-B -M -S Locate Searching for files in the file index database-D UpdateDBUpdate file Index DatabaseFind [path] Find Files-name -iname -path -ipath -amin -atime -cmin -ctime -anewer -cnewer -size -type -user -uid -group -gid -empty Finding empty filesFind the line matching the specified string from the file contents:$
Tags: linux grep head tailThe Grep\head\tail command usesTest.txt12345678910TestLiyaoOldboy
grep command:1. Exclude text content including Oldbody characters (grep-v command exclusions)[[emailprotected] kang]# grep -v "oldboy" t
The grep command in a Linux system is a powerful text search tool that uses regular expressions to search for text and print matching rows. The grep full name is global Regular Expression Print, which represents the global regular expression version, and its use permissions are all users.
grep works like this by searc
Top with awk, medium with SED, standard grep我们都知道,在Linux中一切皆文件,比如配置文件,日志文件,启动文件等等。如果我们相对这些文件进行一些编辑查询等操作时,我们可能会想到一些vi,vim,cat,more等命令。但是这些命令效率不高,这就好比一块空地准备搭建房子,请了10个师傅拿着铁锹挖地基,花了一个月的时间才挖完,而另外一块空地则请了个挖土机,三下五除二就搞定了,这就是效率。而在linux中的“挖土机”有三种型号:顶配awk,中配sed,标配grep。使用这些工具,我们能够在达到同样效果的前提下节省大量的重复性工作,提高效率。接下来我们就看一下sed的详细说明sed 是Stre
, not recommended)-I: Direct editing, this time is really changing the contents of the file, and everything else just change the display. (Not recommended)Action:A is added, a string is followed by a, and the string appears on a new line. (Next line)C supersedes, C-strings, which can replace rows between n1,n2D Delete, not after anything.I insert, followed by a string that appears on the previous lineP prints, lists selected data, usually works with Sed-n sed-n ' 3p ' only prints line 3s substit
Sometimes, we need to find some content in the document, commonly used grep. It finds relevant content in the document and outputs matching rows.> Find a keywordIn System.log, find the row that contains the keywordgrep ' keyword ' System.logOutput line numbers are included in the search for easy viewinggrep ' keyword ' System.log> Basic Regular expressions supported by defaultFind lines that start with 2015-09-24grep ' ^2015-09-24 ' System.log> suppor
times up to N times, less than the base regular expression curly bracesAnchor character:\Group:(): No need to add \ support \1,\2,\3,...Or:|:or orEg:a|b A or BEg:c|cat==c or cat (not cat or cat)grep: Searches for text according to the pattern and displays lines of text that conform to the pattern. a command that uses a basic regular expression and its defined pattern to filter text. Pattern: The matching criteria for the combination of meta-character
Encountered a problem when querying the log found that there are many files printed on the server, each of which stores a portion of the log, the log needs to be sorted by time and all logs are displayed.Original command:grep-h searchcontent */*log The search results will show all the contents in the following format:File1.log: time .... File2.log: time .... Because the log after the file name also contains :, so the use of separators : The method of separating sorting is not feasible, at this t
;: A position that matches the end of a word.
\b: Matches the start or end of a word.
\b: Matches the position of the beginning or end of a word (the middle position of the word).
3, grep options:
(1)-e: Supports extension of regular expressions. grep defaults to the baseline mode.
(2)-r: Recursive search file.
(3)-O: Outputs only the results that match.
(4)-V:
# grep [-ACINV] [--color=auto] ' search string ' filenameOptions and Parameters:-C: Calculates the number of ' search string ' found-I: Ignores case differences, so case is considered the same-N: Output line number by the way-V: Reverse selection, which shows the line without the ' search string ' content=========================Cases:-C: Calculates the number of ' search string ' found[Email protected] ~]# CAT/ETC/PASSWD |
beginning of the/etc/rc.d/init.d/functions file that has a word (including an underscore) followed by a parenthesis [Email protected] ~]# egrep "[_[:alpha:]]+\ (\)"/etc/rc.d/init.d/functions650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M00/9D/4E/wKiom1l93FqBon3VAABUs0xSlLY259.png "title=" i[n$ Ie@l8 ' c3u0kr@09s)]i.png "alt=" Wkiom1l93fqbon3vaabus0xslly259.png "/>4. Use Egrep to remove its base name in/etc/rc.d/init.d/functions[Email protected] ~]# echo "/etc/rc.d/init.d/functions" |
beginning of the/etc/rc.d/init.d/functions file that has a word (including an underscore) followed by a parenthesis [Email protected] ~]# egrep "[_[:alpha:]]+\ (\)"/etc/rc.d/init.d/functions650) this.width=650; "src=" Https://s1.51cto.com/wyfs02/M00/9D/4E/wKiom1l93FqBon3VAABUs0xSlLY259.png "title=" i[n$ Ie@l8 ' c3u0kr@09s)]i.png "alt=" Wkiom1l93fqbon3vaabus0xslly259.png "/>4. Use Egrep to remove its base name in/etc/rc.d/init.d/functions[Email protected] ~]# echo "/etc/rc.d/init.d/functions" |
Http://blog.sina.com.cn/s/blog_62e7fe670101dg9d.htmlLinux find a method that matches multiple keywords in GREP at a time by finding multiple specified files or excluding certain types of files(1) Linux find more than one specified file at a time:Find a.html and b.html
find.-name "a.html"-name "b.html"
Find. -regex '. *\.txt\|. *\.doc\|. *\.mp3 '
find.-regex '. *\.txt\|. *\.doc\|. *\.mp3 '
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.