当前位置:网站首页>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 .
边栏推荐
- Gcc9.5 offline installation
- Haas506 2.0 development tutorial - Alibaba cloud OTA - PAC firmware upgrade (only supports versions above 2.2)
- Summary of data analysis steps
- How can Huawei online match improve the success rate of player matching
- Deployment of Jenkins under win7
- Emotional analysis of wechat chat records on Valentine's day based on Text Mining
- POJ 3237 tree (tree chain splitting)
- Matlab | app designer · I used Matlab to make a real-time editor of latex formula
- 从零开始实现lmax-Disruptor队列(四)多线程生产者MultiProducerSequencer原理解析
- 冯唐“春风十里不如你”数字藏品,7月8日登录希壤!
猜你喜欢
2.2.5 basic sentences of R language drawing
Simple interest mode - evil Chinese style
Teach yourself to train pytorch model to Caffe (III)
深信服X计划-网络协议基础 DNS
Cross end solution to improve development efficiency rapidly
Uni app Bluetooth communication
Opérations de lecture et d'écriture pour easyexcel
递归查询多级菜单数据
让开发效率飞速提升的跨端方案
Cold violence -- another perspective of objective function setting
随机推荐
2022-07-03-CKA-粉丝反馈最新情况
使用Aspect制作全局异常处理类
Deeply convinced plan X - network protocol basic DNS
Recursive query of multi-level menu data
大约SQL现场“这包括”与“包括在”字符串的写法
int GetMonth( ) const throw( ); What does throw () mean?
1.2 download and installation of the help software rstudio
Parker driver maintenance COMPAX controller maintenance cpx0200h
EL与JSTL注意事项汇总
Evolution of zhenai microservice underlying framework from open source component encapsulation to self-development
[daily training] 729 My schedule I
场景化面试:关于分布式锁的十问十答
leetcode:1755. Sum of subsequences closest to the target value
阿里云有奖体验:用PolarDB-X搭建一个高可用系统
资深电感厂家告诉你电感什么情况会有噪音电感噪音是比较常见的一种电感故障情况,如果使用的电感出现了噪音大家也不用着急,只需要准确查找分析出什么何原因,其实还是有具体的方法来解决的。作为一家拥有18年品牌
MMAP learning
The primary key is set after the table is created, but auto increment is not set
Access Zadig self-test environment outside the cluster based on ingress controller (best practice)
Incentive mechanism of Ethereum eth
Three components of openpyxl