当前位置:网站首页>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 .
边栏推荐
- MMAP learning
- Teach yourself to train pytorch model to Caffe (I)
- Golang(1)|从环境准备到快速上手
- EasyExcel的讀寫操作
- Robot framework setting variables
- How to prepare for the algorithm interview and answer the algorithm interview questions
- 思特奇加入openGauss开源社区,共同推动数据库产业生态发展
- poj 3237 Tree(樹鏈拆分)
- Deeply convinced plan X - network protocol basic DNS
- The solution to the problem that Oracle hugepages are not used, causing the server to be too laggy
猜你喜欢

Huawei game multimedia service calls the method of shielding the voice of the specified player, and the error code 3010 is returned

DBeaver同时执行多条insert into报错处理

Scenario interview: ten questions and ten answers about distributed locks

Realize the function of verifying whether the user has completed login when browsing the page

Parker driver maintenance COMPAX controller maintenance cpx0200h

阿里云有奖体验:用PolarDB-X搭建一个高可用系统

Some common processing problems of structural equation model Amos software

华为云ModelArts文本分类–外卖评论

Teach yourself to train pytorch model to Caffe (III)

How can Huawei online match improve the success rate of player matching
随机推荐
Experienced inductance manufacturers tell you what makes the inductance noisy. Inductance noise is a common inductance fault. If the used inductance makes noise, you don't have to worry. You just need
Gcc9.5 offline installation
Efficiency difference between row first and column first traversal of mat data types in opencv
int GetMonth( ) const throw( );后面的throw( )什么意思?
Scenario interview: ten questions and ten answers about distributed locks
Ethereum ETH的奖励机制
123456
Codeforces 12D ball tree array simulation 3 sorting elements
Interviewer: will concurrent programming practice meet? (detailed explanation of thread control operation)
POJ 3237 tree (tree chain splitting)
Evolution of zhenai microservice underlying framework from open source component encapsulation to self-development
Problems encountered in office--
Advantages of robot framework
Interview questions for basic software testing
他们主动布局(autolayout)环境的图像编辑器
sql常用语法记录
poj 3237 Tree(樹鏈拆分)
Uni app Bluetooth communication
基于 Ingress Controller 在集群外访问 Zadig 自测环境(最佳实践)
SecureCRT使用提示