在AIX系统上,如何将数据插入到某一行的文件中

问题描述 投票:0回答:2

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

sed aix
2个回答
1
投票

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

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

这更明确地打破了正在发生的事情。


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.
© www.soinside.com 2019 - 2024. All rights reserved.