Linux system regular expressions are string description methods. The main regular expressions are sed, vim, awk, and of course grep regular expressions. In the previous article, we have introduced the use of regular expressions in Linux systems. Today we will focus on the grep regular expressions in Linux. Start
^ anchor line such as::
grep regular expression metacharacters set & lsquo; ^ grep & rsquo; beginning with grep to match all the rows.
$ End of anchor line For example: ‘grep$’ matches all lines ending with grep.
. Match a non-line break character such as: & lsquo; gr.p & rsquo; match gr followed by an arbitrary character, then p.
* Matches zero or more previous characters such as: ‘*grep’ matches all one or more spaces followed by grep. .* Use together to represent any character.
[] Matches characters within a specified range, such as ‘[Gg]rep’ matches Grep and grep.
[^] matches a character that is not within the specified range, such as: ‘[^A-FH-Z]rep& rsquo; matches a letter that does not contain A-R and T-Z at the beginning, followed by the rep line.
/(../) Marks matching characters, such as ‘/(love/)’,love is marked as 1.
/Anchor the beginning of a word, such as: & lsquo; /match the line containing the word starting with grep.
/" Anchor the end of the word, such as & rsquo;grep /"& lsquo; match the line containing the word ending with grep.
x/{m/} Repeat the character x, m times, such as: & rsquo;0/{5/}& lsquo; match the line containing 5 o.
x/{m,/} Repeat the character x, at least m times, such as: & rsquo;o/{5, /} & lsquo; match at least 5 o lines.
x/{m,n/} repeats the character x, at least m times, no more than n times, such as: & rsquo;o/{5,10/}‘ matches 5-10 o Row.
/w matches text and numeric characters, that is, [A-Za-z0-9], such as: & rsquo;G/w*p‘ matches with G followed by zero or more literal or numeric characters, Then there is p.
/b The word locker, such as: ’/bgrep/b‘ matches only grep.
The commonly used grep options are:
-c Output only the number of matching lines.
-i is not case sensitive (only for single characters).
-h Does not display file names when querying multiple files.
-l When querying multiple files, only the file name containing the matching characters is output.
-n Displays matching lines and line numbers.
-s Does not display error messages that do not exist or have no matching text.
-v Displays all lines that do not contain matching text.
-V Display software version information
When using grep matching, it is best to use double quotes to prevent the system from mistaking parameters or special commands, or to match multiple words. Previous12Next page Total 2 pages
In the Linux system command, the exit command and the _exit command seem to be the
Part of the Linux users who installed Red Flag Linux6.0 and Windows dual system, encountered some pr
In the Linux command, the sort command can be used to sort the file lines. Many peo
Some Linux users find that they cant get the lock /var/lib/dpkg/lock while using Li
What should I do if the NAS storage failure causes Linux to fail to start properly?
How to use commands to transfer files between Mac and Linux
How to solve the garbled problem after SecureCRT connects to Linux server
How to install Twisted on Ubuntu?
What if CentOS can't use the scp command?
CentOS 6.2 upgrade yum prompt libotf.so.0 error how to do?
How to solve the blue screen when installing VMWare in Linux?
How to use the vmstat command in Linux
Linux installation of MariaDB database through Yum
Linux installation of Fedora through BFO Step
How to run the compiler with root privileges under Linux?
When prompted to start the vi editor in Linux, prompt E325: What should ATTENTION do?
Win8 boot shows start pxe over ipv4 how to solve?
How do I send feedback to Microsoft in Windows 7 RC?
Win7/win8.1 upgrade win10 official version of the problem Daquan
Tencent solves the serious problem of Win8 version of QQ card death
Win10 input method disappeared the input method icon suddenly disappeared emergency measures
Win8/Win8.1 how to install Office 2010 Free Edition
What if Win10 cannot automatically install the graphics card driver?
Win10 official version of the official original full image download address summary