I would like to take out only persons with name starting with A using awk. 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.
In awk, ==
won't do glob check, it compares two values, check if they are equal. ~
is a regex matching check, it expect a static or dynamic regex expression.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.