当前位置:网站首页>Awk from entry to penetration (6) regular matching
Awk from entry to penetration (6) regular matching
2022-07-04 08:46:00 【Wonderful binary】
awk Of pattern In addition to using simple conditional expressions , You can also use regular expressions .
AWK Regular expressions can be processed easily and efficiently . A large number of complex tasks can be solved by extremely simple regular expressions . Everyone who is proficient in the command line knows the real power of regular expressions .
This chapter will focus on the use of standard regular expressions .awk The regularity of is basically the same as that of ordinary regularity , But in awk You need to use two regular expressions in / wrap up .
spot (Dot)
Dot character (.) You can match all characters except the end of line character . For example, the stool below can match fin, fun, fan wait .
$ echo -e "cat\nbat\nfun\nfin\nfan" | awk '/f.n/'
Executing the above command can get the following results :
fun
fin
fan
OK, let's start
Line start (^) Match the beginning of a line . The following example will output all the characters as strings The The first line .
$ echo -e "This\nThat\nThere\nTheir\nthese" | awk '/^The/'
You can get the following result by executing the above command :
There
Their
End of line
Line end ($) Match the end of a line . In the following example, all characters will be output n The ending line :
$ echo -e "knife\nknow\nfun\nfin\nfan\nnine" | awk '/n$/'
You can get the following result by executing the above command :
Ca
fin
fan
Match character set
Matching character sets are used to match sets ( Denoted by square brackets ) A character in . In the following example , matching Call And Tall It doesn't match Ball.
$ echo -e "Call\nTall\nBall" | awk '/[CT]all/'
You can get the following result by executing the above command :
Call
Tall
Exclusion set
Regular matching excludes characters from the set . In the following example, only Ball.
$ echo -e "Call\nTall\nBall" | awk '/[^CT]all/'
You can get the following result by executing the above command :
Ball
or
A vertical bar (|) Allow regular expressions to implement logic or operations . The following example will output Ball And Call .
$ echo -e "Call\nTall\nBall\nSmall\nShall" | awk '/Call|Ball/'
You can get the following result by executing the above command :
Call
Ball
Once at most
The symbol ( ?) The preceding character does not appear or appears once . The following example matches Colour And Color. Use ? bring u Becomes an optional character .
$ echo -e "Colour\nColor" | awk '/Colou?r/'
You can get the following result by executing the above command :
Colour
Color
Zero or more times
The symbol (*) Allow the character before it to appear multiple times or not . The following example will match ca,cat, catt wait .
$ echo -e "ca\ncat\ncatt" | awk '/cat*/'
You can get the following result by executing the above command :
ca
cat
catt
One or more times
The symbol (+) Make the character before it appear one or more times . The following example will match a 2 Or multiple consecutive 2.
$ echo -e "111\n22\n123\n234\n456\n222" | awk '/2+/'
You can get the following result by executing the above command :
22
123
234
222
grouping
Brackets are used for grouping and characters | Used to provide a variety of options . The following regular expression will match all that contain Apple Juice or Aplle Cake The line of .
$ echo -e "Apple Juice\nApple Pie\nApple Tart\nApple Cake" | awk '/Apple (Juice|Cake)/'
You can get the following result by executing the above command :
Apple Juice
Apple Cake
Multiple expressions can use && perhaps , come together , The meaning of and :
awk ‘/^ Start time date /,/^ End time date /’ nginx.log
such as , Query time period 2021-03-24 10:12:12 To 2021-09-24 10:12:12,
It can be used awk ‘/^2021-03-24 10:12:*/,/^2021-09-24 10:12:*/’ nginx.log Inquire about .
边栏推荐
- 2022 gas examination registration and free gas examination questions
- Manjaro install wechat
- Add log file to slim frame - PHP
- Educational Codeforces Round 119 (Rated for Div. 2)
- Laravel page load problem connection reset - PHP
- Comprendre la méthode de détection des valeurs aberrantes des données
- Flutter integrated amap_ flutter_ location
- Ehrlich sieve + Euler sieve + interval sieve
- Take you to master the formatter of visual studio code
- awk从入门到入土(18)gawk线上手册
猜你喜欢
Sports [running 01] a programmer's half horse challenge: preparation before running + adjustment during running + recovery after running (experience sharing)
Manjaro install wechat
How to play dapr without kubernetes?
Famous blackmail software stops operation and releases decryption keys. Most hospital IOT devices have security vulnerabilities | global network security hotspot on February 14
DM8 command line installation and database creation
How to re enable local connection when the network of laptop is disabled
How college students choose suitable computers
How does Xiaobai buy a suitable notebook
SSRF vulnerability exploitation - attack redis
The basic syntax of mermaid in typera
随机推荐
ArcGIS application (XXII) ArcMap loading lidar Las format data
AI Winter Olympics | is the future coming? Enter the entrance of the meta universe - virtual digital human
awk从入门到入土(8)数组
MySQL relearn 1-centos install mysql5.7
awk从入门到入土(12)awk也可以写脚本,替代shell
地平线 旭日X3 PI (一)首次开机细节
DM8 database recovery based on point in time
How to send pictures to the server in the form of file stream through the upload control of antd
Educational Codeforces Round 119 (Rated for Div. 2)
How to get bytes containing null terminators from a string- c#
PHP session variable passed from form - PHP
C # implements a queue in which everything can be sorted
yolov5 xml数据集转换为VOC数据集
Codeforces Round #803 (Div. 2)(A-D)
Famous blackmail software stops operation and releases decryption keys. Most hospital IOT devices have security vulnerabilities | global network security hotspot on February 14
2022 electrician (intermediate) examination question bank and electrician (intermediate) examination questions and analysis
ctfshow web255 web 256 web257
团体程序设计天梯赛-练习集 L1-006 连续因子
Group programming ladder race - exercise set l2-002 linked list de duplication
Difference between static method and non static method (advantages / disadvantages)