如何插入在文件的开始的文本? [英] How to insert a text at the beginning of a file?

查看:136
本文介绍了如何插入在文件的开始的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

到目前为止,我已经能够找到如何在文件的开头添加一行但是这不正是我想要的。我会告诉它放在一个例子

So far I've been able to find how to add a line at the beginning of a file but that's not exactly what I want. I'll show it on a example

文件的内容

some text at the beginning

结果

<added text> some text at the beginning

这是类似的,但我不希望创建任何新的符合它...

It's similar but I don't want to create any new line with it...

我想与 SED 如果可能的话,要做到这一点

I would like to do this with sed if possible.

推荐答案

SED 可以在一个地址进行操作:

sed can operate on an address:

$ sed -i '1s/^/<added text> /' file

或者你也可以使用 命令分组

$ { echo -n '<added text> '; cat file; } >file.new
$ mv file{.new,}

这篇关于如何插入在文件的开始的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆