在Linux中的特定行将文本添加到文件 [英] Add text to file at certain line in Linux

查看:166
本文介绍了在Linux中的特定行将文本添加到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想添加一个特定行,比如说avatar到以MakeFile开头的文件中,并且avatar应该添加到文件的第15行中.

I want to add a specific line, lets say avatar to the files that starts with MakeFile and avatar should be added to the 15th line in the file.

这是向文件中添加文本的方法:

This is how to add text to files:

echo 'avatar' >> MakeFile.websvc

这是如何向以MakeFile开头的文件中添加文本的方法:

and this is how to add text to files that starts with MakeFile I think:

echo 'avatar' >> *MakeFile.

但是我无法将此行添加到文件的第15行.

But I can not manage to add this line to the 15th line of the file.

推荐答案

您可以使用sed解决此问题:

You can use sed to solve this:

sed "15i avatar" Makefile.txt

或使用-i选项保存对文件所做的更改.

or use the -i option to save the changes made to the file.

sed -i "15i avatar" Makefile.txt

要更改所有以Makefile开头的文件:

To change all the files beginning that start Makefile:

sed "15i avatar" Makefile*

注意:在上面的15中,是您放置文本所感兴趣的行.

Note: In the above 15 is your line of interest to place the text.

这篇关于在Linux中的特定行将文本添加到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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