免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3978 | 回复: 6
打印 上一主题 下一主题

如何用sed将一行替换成两行 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-11-10 19:26 |只看该作者 |倒序浏览
如:
将text
替换成  text
            abc

论坛徽章:
0
2 [报告]
发表于 2005-11-10 19:49 |只看该作者
sed '/text/a  abc' filename

论坛徽章:
0
3 [报告]
发表于 2005-11-10 23:09 |只看该作者
$more test.txt
text

$sed 's/$/\
>abc/' test.txt
text
abc


$sed '/text/a\
>abc' test.txt
text
abc

[ 本帖最后由 anfield 于 2005-11-11 00:09 编辑 ]

论坛徽章:
0
4 [报告]
发表于 2005-11-11 00:05 |只看该作者
for further interest in related sed commands :
(from Sed & Awk 2nd Edition)

append [line-address]a
text
The append command places it after the current line.

insert [line-address]i
text
The insert command places the supplied text before the current line in the pattern space.

change [address]c
text
The change command replaces the contents of the pattern space
with the supplied text.


Each of these commands requires a backslash following it to escape the first end-of-line. The text must begin on the next line.

论坛徽章:
0
5 [报告]
发表于 2005-11-11 10:07 |只看该作者
$cat aaa
aaaa
$sed -i 's/aaaa/bbbbncccc/g' aaa
$cat aaa
bbbb
cccc

论坛徽章:
0
6 [报告]
发表于 2005-11-11 10:49 |只看该作者
谢谢楼上的各位兄弟了!!!!

论坛徽章:
0
7 [报告]
发表于 2005-11-11 12:35 |只看该作者
sed '/text/s/text/& nabc/' test.txt
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP