[英]Ways to find records based on their first letter awk Unix
I would like to take out only persons with name starting with A using awk. 我只想使用awk删除名称以A开头的人。 How do i do it
我该怎么做
REGNO NAME DEPT AVG STATUS
100 Tony ECE 30 FAIL
200 Jimmy ECE 67 PASS
300 Sanjay CSE 89 PASS
400 Nethra IT 90 PASS
500 Ramesh MECH 45 FAIL
600 Ranjani CSE 34 FAIL
700 Aarthi IT 56 PASS
800 Ram MECH 98 PASS
awk '{if($2=="A*" && $3=="IT" ) print $2,$3}' output.txt
I used this. 我用这个 What is wrong?
怎么了?
awk '$2 ~ "^A" && $3 == "IT" {print $2, $3}'
没有通配符匹配,例如== "A*"
This will work for you: 这将为您工作:
kent$ awk '$2~/^A/&&$3=="IT"{print $2,$3}' file
Aarthi IT
Your problem is, confused by glob and regex. 您的问题是,被glob和regex所混淆。
In awk, ==
won't do glob check, it compares two values, check if they are equal. 在awk中,
==
不会进行全局检查,它会比较两个值,检查它们是否相等。 ~
is a regex matching check, it expect a static or dynamic regex expression. ~
是正则表达式匹配检查,它期望使用静态或动态正则表达式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.