当前位置:网站首页>Shell script, awk condition judgment and logic comparison &||
Shell script, awk condition judgment and logic comparison &||
2022-07-05 21:46:00 【Excellent dengzonglei】
Shell Script ,awk conditional if Compare with logic &&,||
O、 Some problems solved by conditional judgment :
1、 Output all rows or partial rows ,
2、 Part of the data content of the output line ,
3、 Set multiple conditions
grammar :
awk [ Options ]’[ Conditions ]{ Instructions }’ dir
Conditions can be filled in : Regular expressions , The number / Character comparison , Logical comparison
One 、 Regular
~ matching ,!~ Mismatch
1、awk ‘/^ro/{print $1,$7}’ dir
With : For the separator , The print file contains ro The first and seventh columns of the first content line
2、awk -F: ‘$7!~/bash$/{print $1,$7}’ dir
With : For the separator , The seventh column in the specified file does not begin with bash The line at the end , Print its first and seventh columns
3、awk -F: ‘$7~/bash$/{print $1,$7}’ dir
With : For the separator , The seventh column in the specified file is marked with bash The line at the end , Print its first and seventh columns , If the number of columns $ There is no ~ If you receive regular, you will report a syntax error .
Two 、 The number , String comparison , image if But omitted if
== be equal to ,!= It's not equal to ,> Greater than ,>= Greater than or equal to ,< Less than ,<= Less than or equal to
1、awk ‘NR==2{print}’ dir
The print line number is 2 The content of the line
2、awk -F: ‘$7!="/bin/bash"’ dir
With : Separator , Print the seventh column string, which is not "/bin/bash" All line contents of the line of
3、awk -F: ‘$3>=1000{print $1}’ dir
With : Separator , Print the third column of numbers greater than or equal to 1000 The first column of the row content of
4、awk ‘NR%2==0’ dir
Print the contents of all even lines of the specified file
3、 ... and 、、 Logical comparison
&& Logic and
awk -F: ‘$3>=0&&$3<2{print $1,$3}’ /etc/passwd
With : Separator , Print the third column of numbers greater than or equal to 0, And less than 2 The first and third columns of the row of .
|| Logic or
awk -F: ‘$30||$32{print $1,$3}’ /etc/passwd
With : Separator , Print the third column of numbers equal 0, Or equal to 2 The first and third columns of the row of .
边栏推荐
- The solution to the problem that Oracle hugepages are not used, causing the server to be too laggy
- KingbaseES V8R3集群维护案例之---在线添加备库管理节点
- 力扣------经营摩天轮的最大利润
- postgis 安装地理信息扩展
- Robot framework setting variables
- 秋招将临 如何准备算法面试、回答算法面试题
- Xlrd common operations
- Get JS of the previous day (timestamp conversion)
- Selenium finds the contents of B or P Tags
- poj 3237 Tree(樹鏈拆分)
猜你喜欢
让开发效率飞速提升的跨端方案
面试官:并发编程实战会吗?(线程控制操作详解)
2022-07-03-CKA-粉丝反馈最新情况
Defect detection - Halcon surface scratch detection
Realize the function of verifying whether the user has completed login when browsing the page
How to prepare for the algorithm interview and answer the algorithm interview questions
Efficiency difference between row first and column first traversal of mat data types in opencv
力扣------经营摩天轮的最大利润
張麗俊:穿透不確定性要靠四個“不變”
Teach yourself to train pytorch model to Caffe (I)
随机推荐
让开发效率提升的跨端方案
Kingbasees v8r3 cluster maintenance case -- online addition of standby database management node
Selenium gets the verification code image in DOM
What should I do to prepare for the interview algorithm position during school recruitment?
Deeply convinced plan X - network protocol basic DNS
Drawing HSV color wheel with MATLAB
matlab绘制hsv色轮图
How to organize an actual attack and defense drill
Interviewer: will concurrent programming practice meet? (detailed explanation of thread control operation)
Clickhouse copy paste multi line SQL statement error
总结出现2xx、3xx、4xx、5xx状态码的原因
Image editor for their AutoLayout environment
Xlrd common operations
华为游戏多媒体调用切换房间方法出现异常Internal system error. Reason:90000017
Zhang Lijun: la pénétration de l’incertitude dépend de quatre « invariants»
Making global exception handling classes with aspect
KingbaseES V8R3集群维护案例之---在线添加备库管理节点
DBeaver同时执行多条insert into报错处理
Summarize the reasons for 2XX, 3xx, 4xx, 5xx status codes
Huawei fast game failed to call the login interface, and returned error code -1