在AIX系统上,如何在特定行将数据插入文件

时间:2019-02-26 08:44:15

标签: sed aix

在AIX测试系统上,我想在某些行将一些数据插入文件中。我尝试使用sed命令sed "5i some_data" somefile.txt,但失败了。有什么建议吗?

2 个答案:

答案 0 :(得分:1)

sed更适合编辑流;您可以在文件上使用可编写脚本的文本编辑器。 edex的示例:

ed somefile.txt <<EOE
5i
some data
.
wq
EOE

这可以更明确地分解正在发生的事情。

答案 1 :(得分:0)

AIX sedrequiring 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.