当前位置:网站首页>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 .
边栏推荐
- 华为云ModelArts文本分类–外卖评论
- Summary of El and JSTL precautions
- MMAP
- 大约SQL现场“这包括”与“包括在”字符串的写法
- 阿里云有奖体验:用PolarDB-X搭建一个高可用系统
- SecureCRT使用提示
- GCC9.5离线安装
- Opérations de lecture et d'écriture pour easyexcel
- Access Zadig self-test environment outside the cluster based on ingress controller (best practice)
- poj 3237 Tree(樹鏈拆分)
猜你喜欢

MMAP learning

MATLAB | App Designer·我用MATLAB制作了一款LATEX公式实时编辑器

面试官:并发编程实战会吗?(线程控制操作详解)

MMAP

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

基于 Ingress Controller 在集群外访问 Zadig 自测环境(最佳实践)

R language learning notes

2022-07-03-cka- latest feedback from fans

Interviewer: will concurrent programming practice meet? (detailed explanation of thread control operation)

An exception occurred in Huawei game multimedia calling the room switching method internal system error Reason:90000017
随机推荐
sql常用语法记录
从零开始实现lmax-Disruptor队列(四)多线程生产者MultiProducerSequencer原理解析
Net small and medium-sized enterprise project development framework series (one)
ESP32
one hundred and twenty-three thousand four hundred and fifty-six
华为游戏多媒体服务调用屏蔽指定玩家语音方法,返回错误码3010
Objects in the list, sorted by a field
NET中小型企业项目开发框架系列(一个)
Feng Tang's "spring breeze is not as good as you" digital collection, logged into xirang on July 8!
Parker驱动器维修COMPAX控制器维修CPX0200H
2022-07-03-CKA-粉丝反馈最新情况
Oracle HugePages没有被使用导致服务器很卡的解决方法
Deployment of Jenkins under win7
MySQL InnoDB Architecture Principle
张丽俊:穿透不确定性要靠四个“不变”
Summarize the reasons for 2XX, 3xx, 4xx, 5xx status codes
Analysis and test of ModbusRTU communication protocol
Realize the function of verifying whether the user has completed login when browsing the page
SQL knowledge leak detection
资深电感厂家告诉你电感什么情况会有噪音电感噪音是比较常见的一种电感故障情况,如果使用的电感出现了噪音大家也不用着急,只需要准确查找分析出什么何原因,其实还是有具体的方法来解决的。作为一家拥有18年品牌