sed 在行首添加字符
[root@localdomain test] # cat test.file
abc
bcd
[root@localdomain test] # sed 's/^/\#/g' test.file
#abc
#bcd
sed 在行尾添加字符
[root@localdomain test] # cat test.file
abc
bcd
[root@localdomain test] # sed 's/$/\#/g' test.file
abc#
bcd#
sed 同时在行首、行尾添加字符
kayson@kayson-virtual-machine:~$ cat zhenghe.txt
abc
bcd
kayson@kayson-virtual-machine:~$ sed -i -e 's/^/\#/g' -e 's#$#\##g' zhenghe.txt
###abc#####
#######
##bcd#####
sed 在指定行添加字符,在2--5行之间添加字符
kayson@kayson-virtual-machine:~$ sed '2,5s/^/\#/g' datafile
sed合并奇偶行
[root@localhost ~]# cat file
1
2
3
4
5
6
7
8
9
10
[root@localhost ~]# sed 'N;s/\n//g' file
12
34
56
78
910
# 从30行到最后一行,添加注释
sed -i '30,$s/^/#/' /etc/keepalived/keepalived.conf
阅读(1072) | 评论(0) | 转发(0) |