LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1265|回复: 5

如何把一行文字添加的一个文件的头部啊

[复制链接]
发表于 2008-10-17 14:46:31 | 显示全部楼层 |阅读模式
文件内容
abc
def
ghi

把123追加abc前面去, 应该如何做?

谢谢
发表于 2008-10-17 15:41:37 | 显示全部楼层
可以用ed脚本。

cat script.ed :
1
i
123
.
w
q

把这个文加cat给ed :
cat script.ed | ed yourfile
回复 支持 反对

使用道具 举报

 楼主| 发表于 2008-10-19 20:42:46 | 显示全部楼层

找到方法了, 用sed -e, 呵呵

[linuxsir@linuxsir bin]$ cat /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1               localhost.localdomain localhost
[linuxsir@linuxsir bin]$ cat /etc/hosts | sed -e'1ihello world!'
hello world!
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1               localhost.localdomain localhost
回复 支持 反对

使用道具 举报

发表于 2008-10-20 19:25:34 | 显示全部楼层
ed vs. sed ...
回复 支持 反对

使用道具 举报

发表于 2008-10-24 16:09:05 | 显示全部楼层
为什么不用>>呢?
回复 支持 反对

使用道具 举报

发表于 2008-10-28 10:06:06 | 显示全部楼层
我认为最好的方法:
cat - file <<< 123
回复 支持 反对

使用道具 举报

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

本版积分规则

快速回复 返回顶部 返回列表