在AIX测试系统上,我想在某些行将一些数据插入文件中。我尝试使用sed命令sed "5i some_data" somefile.txt
,但失败了。有什么建议吗?
答案 0 :(得分:1)
sed
更适合编辑流;您可以在文件上使用可编写脚本的文本编辑器。 ed
或ex
的示例:
ed somefile.txt <<EOE
5i
some data
.
wq
EOE
这可以更明确地分解正在发生的事情。
答案 1 :(得分:0)
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.