在Emacs中执行此操作的唯一方法是访问该文件,在相关缓冲区的顶部插入两行,并将缓冲区写入磁盘.但实际上,Emacs是这项工作的错误工具.您应该在命令行上执行此操作.
实现这一目标的一种简单方法是使用cat:
cat - /path/to/input-file >/path/to/output-file <<EOF
Run Code Online (Sandbox Code Playgroud)
在该命令之后,您可以在shell中键入两行,并在第三行写入EOF.然后,这将在文件的顶部插入这两行,并将结果写入output-file.例如:
cat - /path/to/huge-file >/path/to/output-file <<EOF
> This is the first line
> This is the second line
> EOF
Run Code Online (Sandbox Code Playgroud)
如果必须对许多文件执行此操作,将两行写入单独的文件是有意义的,因此您不必每次都键入它们.然后你会做:
cat /path/to/two-line-file /path/to/huge-file >/path/to/output-file
Run Code Online (Sandbox Code Playgroud)