shell之awk(三)运算符匹配

% awk 'BEGIN{FS=":"}$3<30{print $0}' /etc/passwd. //匹配第3列小于30的
nobody:*:-2:-2:Unprivileged User:/var/empty:/usr/bin/false
root:*:0:0:System Administrator:/var/root:/bin/sh
daemon:*:1:1:System Services:/var/root:/usr/bin/false
_uucp:*:4:4:Unix to Unix Copy Protocol:/var/spool/uucp:/usr/sbin/uucico
_taskgated:*:13:13:Task Gate Daemon:/var/empty:/usr/bin/false
_networkd:*:24:24:Network Services:/var/networkd:/usr/bin/false
_installassistant:*:25:25:Install Assistant:/var/empty:/usr/bin/false
_lp:*:26:26:Printing Services:/var/spool/cups:/usr/bin/false
_postfix:*:27:27:Postfix Mail Server:/var/spool/postfix:/usr/bin/fals
% awk 'BEGIN{FS=":"}$7=="/bin/sh"{print $0}' /etc/passwd   //第7列等于/bin/sh的
root:*:0:0:System Administrator:/var/root:/bin/sh
awk 'BEGIN{FS=":"}$1~/root/{print $0}' /etc/passwd. //第一例匹配root的
root:*:0:0:System Administrator:/var/root:/bin/sh
_cvmsroot:*:212:212:CVMS Root:/var/empty:/usr/bin/false
% awk 'BEGIN{FS=":"}$1=="root" || $1=="_hidd"{print $0}' /etc/passwd
root:*:0:0:System Administrator:/var/root:/bin/sh
_hidd:*:261:261:HID Service User:/var/db/hidd:/usr/bin/false

 

运算符

<  小于

> 大于

<= 小于等于

>=大于等于

== 等于

!= 不等于

~匹配正则

!~不匹配

|| 或

!非

&&并且

posted @ 2018-02-27 17:37  温柔的风  阅读(232)  评论(0编辑  收藏  举报