proc /proc proc defaults 0 0
5)、删除第一个#号开头的行到第一个"/",开头的行:
[root@localhost ~]# sed '/^#/,/^\//d' /etc/fstab
UUID=2020ea71-49cf-488e-bd6c-de72a001082b /boot ext4 defaults 1 2
/dev/mapper/VolGroup-lv_swap swap swap defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
-p 打印参数
6)、打印第一个#号开头的行到第一个"/",开头的行,如果不加-n参数静默模式,会输出重复匹配的内容:
[root@localhost ~]# sed -n '/^#/,/^\//p' /etc/fstab
#
# /etc/fstab
# Created by anaconda on Fri Feb 24 02:20:51 2017
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/VolGroup-lv_root / ext4 defaults 1 1
不加-n参数结果:
[root@localhost ~]# sed '/^#/,/^\//p' /etc/fstab
#
#
# /etc/fstab
# /etc/fstab
# Created by anaconda on Fri Feb 24 02:20:51 2017
# Created by anaconda on Fri Feb 24 02:20:51 2017
#
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
#
/dev/mapper/VolGroup-lv_root / ext4 defaults 1 1
/dev/mapper/VolGroup-lv_root / ext4 defaults 1 1
UUID=2020ea71-49cf-488e-bd6c-de72a001082b /boot ext4 defaults 1 2
/dev/mapper/VolGroup-lv_swap swap swap defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
a和i参数:
a:在匹配的行之后添加内容
i: 在匹配的行之前添加内容
#再#号开头的行之后添加hello world
# sed '/^#/a \hello world' /etc/fstab
#
hello world
# /etc/fstab
hello world
# Created by anaconda on Fri Feb 24 02:20:51 2017
hello world
#
hello world
# Accessible filesystems, by reference, are maintained under '/dev/disk'
hello world
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
hello world
#
hello world
/dev/mapper/VolGroup-lv_root / ext4 defaults 1 1
UUID=2020ea71-49cf-488e-bd6c-de72a001082b /boot ext4 defaults 1 2
/dev/mapper/VolGroup-lv_swap swap swap defaults 0 0