awk编辑器

awk -F: '$1 == "root"{print $1,NR,NF}' /etc/passwd 注意这里的$不是取值符号
awk -F: 'NR>20 || NR<3{print $1,$3,$NF}' /etc/passwd
awk -F: 'NR>1 && NR<3{print $1,NR,NF}' /etc/passwd
awk -F: 'NR>1 && NR<4{print $1,NR,NF}' /etc/passwd
awk -F: '$1~/^r/{print $1,NR,NF}' /etc/passwd
awk -F: '/^root/{print $1,NR,NF}' /etc/passwd

username=root
awk -v var=$username -F: '$1 == var{print $1,NR,NF}' /etc/passwd

awk作业

打印uid在3~5范围内的用户名。

[root@myworld ~]# awk -F: '$3>=3&&$3<=5{print $0}' test

打印第5-10行的行号和用户名

[root@myworld ~]# awk -F: 'NR>=5&&NR<=10{print NR,$1}' test

打印奇数行

[root@myworld ~]# awk -F: 'NR%2==1{print $0,NR}' test
打印偶数行

[root@myworld ~]# awk -F: 'NR%2==0{print $0,NR}' test
打印字段数大于5的行

[root@myworld ~]# awk -F: 'NF>5{print $0}' test
打印UID不等于GID的用户名

[root@myworld ~]# awk -F: '$3!=$4{print $1}' test
打印没有指定shell的用户

[root@myworld ~]# awk -F: '$NF!="/bin/bash"{print $0}' test

转载于:https://www.cnblogs.com/Icarus1900/p/7689187.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值