当前位置:网站首页>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 .
边栏推荐
- Flutter integrated amap_ flutter_ location
- Snipaste convenient screenshot software, which can be copied on the screen
- Fault analysis | MySQL: unique key constraint failure
- 埃氏筛+欧拉筛+区间筛
- awk从入土到入门(10)awk内置函数
- Comparison between sentinel and hystrix
- Technology sharing | MySQL parallel DDL
- [attack and defense world | WP] cat
- 没有Kubernetes怎么玩Dapr?
- How to play dapr without kubernetes?
猜你喜欢
How does Xiaobai buy a suitable notebook
What sparks can applet container technology collide with IOT
DM8 uses different databases to archive and recover after multiple failures
The second session of the question swiping and punching activity -- solving the switching problem with recursion as the background (I)
Azure ad domain service (II) configure azure file share disk sharing for machines in the domain service
ctfshow web255 web 256 web257
From scratch, use Jenkins to build and publish pipeline pipeline project
Educational Codeforces Round 115 (Rated for Div. 2)
微服务入门:Gateway网关
OpenFeign 服务接口调用
随机推荐
团体程序设计天梯赛-练习集 L1-006 连续因子
微服務入門:Gateway網關
Conversion of yolov5 XML dataset to VOC dataset
L1 regularization and L2 regularization
es6总结
埃氏筛+欧拉筛+区间筛
snipaste 方便的截图软件,可以复制在屏幕上
Codeforces Round #803 (Div. 2)(A-D)
ArcGIS application (XXII) ArcMap loading lidar Las format data
Comparison between sentinel and hystrix
Four essential material websites for we media people to help you easily create popular models
Basic discipline formula and unit conversion
一文了解數據异常值檢測方法
Mouse over to change the transparency of web page image
deno debugger
[attack and defense world | WP] cat
The right way to capture assertion failures in NUnit - C #
How does Xiaobai buy a suitable notebook
Codeforces Round #750 (Div. 2)(A,B,C,D,F1)
Call Baidu map to display the current position