例题:
1、找出"netstat -tan”命令的结果中,以‘LISTEN’后跟0或多个空白字符结尾的行
2、在/etc/fstab文件中不以#开头的行的行首增加#号
3、删除/etc/fstab文件中所有以#开头的#字符
实现:
例1:
[root@localhost ~]# netstat -tan | grep -E "\<LISTEN\>([ ]*|[0])"
[root@localhost ~]# netstat -tan | grep '\<LISTEN\>'
例2:
[root@localhost ~]# sed -r 's/^[^\#]/#&/' /etc/fstab
例3:
[root@localhost ~]# sed "s/^#//" /etc/fstab