我想从 test.txt 中获取前两行:
hello
my
name
is
Run Code Online (Sandbox Code Playgroud)
并将它们放在新文件 output.txt 的顶部:
foo
bar
Run Code Online (Sandbox Code Playgroud)
所需的输出为output.txt:
hello
my
foo
bar
Run Code Online (Sandbox Code Playgroud)
使用 sed。但是,使用:
text=$(head test.txt -n 2) | sed -i "1i $text" output.txt
Run Code Online (Sandbox Code Playgroud)
返回错误:
sed: -e expression #1, char 10: extra characters after command
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
sed ×1