当前位置:网站首页>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 .
边栏推荐
- [daily training -- Tencent select 50] 89 Gray code (only after seeing the solution of the problem)
- regular expression
- HYSBZ 2243 染色 (树链拆分)
- Interview questions for basic software testing
- MMAP
- Deployment of Jenkins under win7
- 1.2 download and installation of the help software rstudio
- Sorting out the problems encountered in MySQL built by pycharm connecting virtual machines
- Objects in the list, sorted by a field
- 初级软件测试必问面试题
猜你喜欢
Parker driver maintenance COMPAX controller maintenance cpx0200h
Evolution of zhenai microservice underlying framework from open source component encapsulation to self-development
Oracle checkpoint queue - Analysis of the principle of instance crash recovery
递归查询多级菜单数据
Drawing HSV color wheel with MATLAB
Exercise 1 simple training of R language drawing
Deeply convinced plan X - network protocol basic DNS
matlab绘制hsv色轮图
Explain various hot issues of Technology (SLB, redis, mysql, Kafka, Clickhouse) in detail from the architecture
Oracle检查点队列–实例崩溃恢复原理剖析
随机推荐
Evolution of zhenai microservice underlying framework from open source component encapsulation to self-development
Poj3414广泛搜索
Teach yourself to train pytorch model to Caffe (2)
Two ways to realize video recording based on avfoundation
NET中小型企业项目开发框架系列(一个)
int GetMonth( ) const throw( ); What does throw () mean?
Kingbasees v8r3 data security case - audit record clearing case
ESP32
Recursive query of multi-level menu data
MMAP学习
Oracle checkpoint queue - Analysis of the principle of instance crash recovery
Kingbasees v8r3 cluster maintenance case -- online addition of standby database management node
POJ 3237 tree (tree chain splitting)
办公遇到的问题--
Uni app Bluetooth communication
How to organize an actual attack and defense drill
one hundred and twenty-three thousand four hundred and fifty-six
华为游戏多媒体服务调用屏蔽指定玩家语音方法,返回错误码3010
Interviewer: will concurrent programming practice meet? (detailed explanation of thread control operation)
Pointer parameter passing vs reference parameter passing vs value parameter passing