Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1075204
  • 博文数量: 120
  • 博客积分: 887
  • 博客等级: 准尉
  • 技术积分: 1883
  • 用 户 组: 普通用户
  • 注册时间: 2010-04-05 21:10
个人简介

RHCE,CCNA,熟悉shell脚本

文章分类

全部博文(120)

文章存档

2015年(16)

2014年(20)

2013年(48)

2012年(20)

2011年(16)

分类: 系统运维

2013-11-26 11:16:49

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
阅读(1028) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~