免费注册 查看新帖 |

Chinaunix

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

请教 怎么样用sed在行首插入字符 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-12-19 20:19 |只看该作者 |倒序浏览
awk 比较简单:

awk '{print 1, $0}'

不知道 sed怎么样做。

论坛徽章:
0
2 [报告]
发表于 2005-12-19 20:56 |只看该作者
你的 awk 代码应该是首列插入的吧?

论坛徽章:
0
3 [报告]
发表于 2005-12-19 20:56 |只看该作者
试试:
sed 's/^/add sth. at the beginning of each line/'

论坛徽章:
0
4 [报告]
发表于 2005-12-19 23:36 |只看该作者
[k@korg tmp]$ cat tt
include /usr/share/xpdf/japanese/add-to-xpdfrc
include /usr/share/xpdf/korean/add-to-xpdfrc
include /usr/share/xpdf/chinese-simplified/add-to-xpdfrc
include /usr/share/xpdf/chinese-traditional/add-to-xpdfrc
[k@korg tmp]$ sed -i 's/^/aa/' tt
[k@korg tmp]$ cat tt
aainclude /usr/share/xpdf/japanese/add-to-xpdfrc
aainclude /usr/share/xpdf/korean/add-to-xpdfrc
aainclude /usr/share/xpdf/chinese-simplified/add-to-xpdfrc
aainclude /usr/share/xpdf/chinese-traditional/add-to-xpdfrc
[k@korg tmp]$ sed -i 's/^aa//' tt
[k@korg tmp]$ cat tt
include /usr/share/xpdf/japanese/add-to-xpdfrc
include /usr/share/xpdf/korean/add-to-xpdfrc
include /usr/share/xpdf/chinese-simplified/add-to-xpdfrc
include /usr/share/xpdf/chinese-traditional/add-to-xpdfrc

论坛徽章:
1
荣誉会员
日期:2011-11-23 16:44:17
5 [报告]
发表于 2005-12-19 23:40 |只看该作者
原帖由 wangrujun 于 2005-12-19 20:19 发表
awk 比较简单:

awk '{print 1, $0}'

不知道 sed怎么样做。

看一下置顶十二篇之SED,就知道了 @_@

论坛徽章:
0
6 [报告]
发表于 2005-12-21 09:48 |只看该作者
原帖由 大蚂蚁 于 2005-12-19 20:56 发表
你的 awk 代码应该是首列插入的吧?


是的。

论坛徽章:
0
7 [报告]
发表于 2005-12-21 09:54 |只看该作者
原帖由 vegetablebird 于 2005-12-19 20:56 发表
试试:
sed 's/^/add sth. at the beginning of each line/'


谢谢

论坛徽章:
0
8 [报告]
发表于 2005-12-21 09:56 |只看该作者
原帖由 toarms 于 2005-12-19 23:36 发表
[k@korg tmp]$ cat tt
include /usr/share/xpdf/japanese/add-to-xpdfrc
include /usr/share/xpdf/korean/add-to-xpdfrc
include /usr/share/xpdf/chinese-simplified/add-to-xpdfrc
include /usr/share/xpdf ...


非常感谢 

论坛徽章:
0
9 [报告]
发表于 2005-12-21 09:59 |只看该作者
原帖由 寂寞烈火 于 2005-12-19 23:40 发表

看一下置顶十二篇之SED,就知道了 @_@


谢谢 @_@
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP