Emacs追加文件内容到另一个文件

Emacs追加文件内容到另一个文件

方法一:插入文件内容(推荐)

打开目标文件后,将光标移动到需要插入的位置(若要追加到文件末尾可执行):

1
M->

然后执行:

1
C-x i

或:

1
M-x insert-file

输入源文件路径,例如:

1
/path/to/source.txt

此时源文件内容会插入到当前光标位置,实现追加效果。

示例:

当前打开:

1
target.txt

移动到文件末尾:

1
M->

插入文件:

1
C-x i

选择:

1
source.txt

则 source.txt 的内容会追加到 target.txt 末尾。

方法二:使用 Shell 命令追加

在 Emacs 的 Shell、Eshell 或终端中执行:

1
cat source.txt >> target.txt

将 source.txt 的内容追加到 target.txt 末尾。

适用于快速合并文件或批量处理场景。