免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12
最近访问板块 发新帖
楼主: ShareThought
打印 上一主题 下一主题

如何在指定的行前面加入一行 [复制链接]

论坛徽章:
1
荣誉会员
日期:2011-11-23 16:44:17
11 [报告]
发表于 2008-06-10 22:30 |只看该作者
waker is right~~~
lee@/home/lee#cat a
abc
home
end
lee@/home/lee#ed a<<EOF
> /home/i
> new line
> .
> w
> q
> EOF
13
22
lee@/home/lee#cat a
abc
new line
home
end
lee@/home/lee#

论坛徽章:
33
ChinaUnix元老
日期:2015-02-02 08:55:39CU十四周年纪念徽章
日期:2019-08-20 08:30:3720周年集字徽章-周	
日期:2020-10-28 14:13:3020周年集字徽章-20	
日期:2020-10-28 14:04:3019周年集字徽章-CU
日期:2019-09-08 23:26:2519周年集字徽章-19
日期:2019-08-27 13:31:262016科比退役纪念章
日期:2022-04-24 14:33:24
12 [报告]
发表于 2008-06-10 23:30 |只看该作者

回复 #11 寂寞烈火 的帖子

What should we do if you have more than one "home"?
I mean I want to add "new line" above every "home".

$ cat urfile
a
home
b
home
$ ed -s urfile <<\EOF
> /home/i
> new line
> .
> w
> q
> EOF
$ cat urfile
a
new line
home
b
home
$

论坛徽章:
0
13 [报告]
发表于 2008-06-10 23:31 |只看该作者
原帖由 waker 于 2008-6-10 08:56 发表
ed -s urfile <<\EOF
/home/i
new line
.
w
q
EOF


赞!这几乎可以替代sed -f和awk -f啦。
每天逛shell版都有收获!
ed -s中的s是什么意思?silence?静默模式吗

论坛徽章:
1
荣誉会员
日期:2011-11-23 16:44:17
14 [报告]
发表于 2008-06-10 23:39 |只看该作者

回复 #13 yuhe27913 的帖子

you are right, too,

  1. -s, -, --quiet, --silent   suppress diagnostics
复制代码

论坛徽章:
0
15 [报告]
发表于 2008-06-11 08:27 |只看该作者
原帖由 寂寞烈火 于 2008-6-10 22:30 发表
waker is right~~~
lee@/home/lee#cat a
abc
home
end
lee@/home/lee#ed a new line
> .
> w
> q
> EOF
13
22
lee@/home/lee#cat a
abc
new line
home
end
lee@/home/lee#


在脚本中怎么写呢?

论坛徽章:
33
ChinaUnix元老
日期:2015-02-02 08:55:39CU十四周年纪念徽章
日期:2019-08-20 08:30:3720周年集字徽章-周	
日期:2020-10-28 14:13:3020周年集字徽章-20	
日期:2020-10-28 14:04:3019周年集字徽章-CU
日期:2019-09-08 23:26:2519周年集字徽章-19
日期:2019-08-27 13:31:262016科比退役纪念章
日期:2022-04-24 14:33:24
16 [报告]
发表于 2008-06-11 10:05 |只看该作者

回复 #5 zhaopingzi 的帖子

明白了,是sed版本的问题。

C:\ProgramMy\GnuWin32>sed "/home/i\new line" urfile
a
new line
home
b
new line
home

C:\ProgramMy\GnuWin32>sed --version
GNU sed version 4.1.5
Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE,
to the extent permitted by law.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP