在AIX测试系统上,我想将某些数据插入某行的文件中。我尝试过使用sed命令sed "5i some_data" somefile.txt
但失败了。有什么建议?
sed
更适合编辑流;您可以在文件上使用可编写脚本的文本编辑器。 ed
或ex
的示例:
ed somefile.txt <<EOE
5i
some data
.
wq
EOE
这更明确地打破了正在发生的事情。
AIX sed在requiring a newline with the i
function是严格的:
cp somefile.txt somefile.txt.orig
sed '5i\
some_data' somefile.txt.orig > somefile.txt
标准表明:
[1addr]i\
text
Write text to standard output.