月辉清照

博客园 首页 新随笔 联系 订阅 管理

1、利用sed 取出ifconfig命令中本机的IPv4地址

[root@localhost]# ifconfig eth0|sed -nr '2s/[^0-9]+([0-9.]+).*/\1/p'
192.168.56.128

2、删除/etc/fstab文件中所有以#开头,后面至少跟一个空白字符的行的行首的#和空白字符

[root@localhost]# sed -r 's/^#[ ]+//g' /etc/fstab

3、处理/etc/fstab路径,使用sed命令取出其目录名和基名

[root@localhost]# echo /etc/fstab |sed -rn 's#(.*)/([^/]+)/?#\1#p'
/etc
[root@localhost]# echo /etc/fstab |sed -rn 's#(.*)/([^/]+)/?#\2#p'
fstab
[root@localhost]#
posted on 2021-08-29 17:32  月辉清照  阅读(40)  评论(0)    收藏  举报