在Linux中的特定行将文本添加到文件 [英] Add text to file at certain line in 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屋!