在AIX系统上,如何在文件的某一行插入数据
On AIX system, how to insert data to file at certain line
在 AIX 测试系统上,我想将一些数据插入文件的特定行。我曾尝试使用 sed 命令 sed "5i some_data" somefile.txt
但失败了。有什么建议吗?
sed
更适合编辑流;您可以在文件上使用可编写脚本的文本编辑器。 ed
或 ex
的示例:
ed somefile.txt <<EOE
5i
some data
.
wq
EOE
这更明确地分解了正在发生的事情。
AIX sed is strict in 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.
在 AIX 测试系统上,我想将一些数据插入文件的特定行。我曾尝试使用 sed 命令 sed "5i some_data" somefile.txt
但失败了。有什么建议吗?
sed
更适合编辑流;您可以在文件上使用可编写脚本的文本编辑器。 ed
或 ex
的示例:
ed somefile.txt <<EOE
5i
some data
.
wq
EOE
这更明确地分解了正在发生的事情。
AIX sed is strict in 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.