当前位置:网站首页>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 .
边栏推荐
- Codeforces 12D Ball 树形阵列模拟3排序元素
- Parker驱动器维修COMPAX控制器维修CPX0200H
- EasyExcel的讀寫操作
- Image editor for their AutoLayout environment
- Why can't Chinese software companies produce products? Abandon the Internet after 00; Open source high-performance API gateway component of station B | weekly email exclusive to VIP members of Menon w
- GCC9.5离线安装
- JMeter installation under win7
- Explain various hot issues of Technology (SLB, redis, mysql, Kafka, Clickhouse) in detail from the architecture
- Some common processing problems of structural equation model Amos software
- Drawing HSV color wheel with MATLAB
猜你喜欢

2022-07-03-CKA-粉丝反馈最新情况

Recursive query of multi-level menu data

Simple interest mode - evil Chinese style

Explain various hot issues of Technology (SLB, redis, mysql, Kafka, Clickhouse) in detail from the architecture

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

Li Kou ----- the maximum profit of operating Ferris wheel

What should I do to prepare for the interview algorithm position during school recruitment?

Teach yourself to train pytorch model to Caffe (2)

Xlrd common operations

华为游戏多媒体调用切换房间方法出现异常Internal system error. Reason:90000017
随机推荐
How can Huawei online match improve the success rate of player matching
Kingbasees v8r3 data security case - audit record clearing case
SQL common syntax records
QML reported an error expected token ";", expected a qualified name ID
MMAP
Uni app Bluetooth communication
Detailed explanation of memset() function usage
Oracle检查点队列–实例崩溃恢复原理剖析
[daily training] 729 My schedule I
初级软件测试必问面试题
他们主动布局(autolayout)环境的图像编辑器
sql常用语法记录
Interviewer: will concurrent programming practice meet? (detailed explanation of thread control operation)
Making global exception handling classes with aspect
Sorting out the problems encountered in MySQL built by pycharm connecting virtual machines
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
poj 3237 Tree(树链拆分)
Scenario interview: ten questions and ten answers about distributed locks
Robot operation mechanism
NET中小型企业项目开发框架系列(一个)