shell每日更新(5)

6月11号 晚上8点半

提取字段用:awk 与cut 如提取passwd中第五个字段。

[root@fsailing1 shell]# awk -F: '{print $1}' /etc/passwd
root
bin
daemon
adm
lp
sync
shutdown
halt
[root@fsailing1 shell]# cut -d: -f 5 /etc/passwd
root
bin
daemon
adm
lp
sync
shutdown
halt
解释下awk中print与printf的区别:没有分开全部按顺序写出来。

[root@fsailing1 ~]# awk -F: '{printf $5}' /etc/passwd
rootbindaemonadmlpsyncshutdownhaltmailnewsuucpoperatorgamesgopherFTP UserNobodyDistcacheNSCD Daemonvirtual console memory ownerApachePortmapper RPC userWebalizerdovecotSystem message busAvahi daemonRPC Service UserAnonymous NFS UserNamedPrivilege-separated SSHHAL daemonavahi-autoipdX Font ServerMySQL Server[root@fsaili

6月12号 下午2点

正则表达式,IP地址的匹配:使用grep的时候不太支持正则表达式,需要转义字符\匹配使用

[root@fsailing1 shell]# cat chen3.txt
192.168.110.1
10.5.110.238
192.184.110.112
1110.333.44.1111
[root@fsailing1 shell]# cat chen3.txt|egrep '([0-9]\{1,3\}\.)\{1,3\}([0-9])\{1,3\}'
[root@fsailing1 shell]# cat chen3.txt|grep '([0-9]\{1,3\}\.)\{1,3\}([0-9])\{1,3\}'
[root@fsailing1 shell]# cat chen3.txt|grep '\([0-9]\{1,3\}\.\)\{1,3\}\([0-9]\)\{1,3\}'
192.168.110.1
10.5.110.238
192.184.110.112
1110.333.44.1111
如果使用egrep就不同了,它是grep里面专门用来匹配正则表达式的。

[root@fsailing1 shell]# cat chen3.txt|egrep '([0-9]\.{1,3}){1,3}([0-9]){1,3}'
192.168.110.1
10.5.110.238
192.184.110.112
1110.333.44.1111






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值