简体   繁体   English

在Linux中将内容从一个文件追加到另一个文件

[英]Append content from one file to another in Linux

I have two files, file1 on server 1 and file2 on server 2. 我有两个文件,服务器1上的file1和服务器2上的file2

Now I want to write a script to append the contents of file2 (from server 2) to file1 (on server 1), that is, without overwriting the original contents. 现在我想编写一个脚本追加的内容file2 (从服务器2) file1 (在服务器1),也就是说,没有覆盖原来的内容。

How can I do this with a shell script (using Ubuntu Linux)? 如何使用Shell脚本(使用Ubuntu Linux)执行此操作?

ssh server2 "cat /path/to/file2" | ssh server1 "cat >> /path/to/file1"

If minimizing network traffic is an issue, use the trickier-to-quote version: 如果最小化网络流量是一个问题,请使用更复​​杂的报价版本:

ssh server2 'cat /path/to/file2 | ssh server1 "cat >> /path/to/file2"'

The first version transfers the file to your local host, then to server1 . 第一个版本将文件传输到本地主机,然后传输到server1 The second version transfers the file directly from server2 to server1 . 第二个版本将文件直接从server2传输到server1 (If either file path contains spaces, the quoting becomes much trickier.) (如果任何一个文件路径都包含空格,则引用会变得更加棘手。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 shell 在 Linux 中将 append 一个文件转换为另一个文件? - How to append one file to another in Linux from the shell? 将一个文件的内容附加到另一个带有缩进的 yaml 文件 - append content of one file to another yaml file with indentation Bash,Linux,需要根据另一个文件中的匹配内容来删除一个文件中的行 - Bash, Linux, Need to remove lines from one file based on matching content from another file 过滤来自特定文件的文本和 append 和 output 到另一个文件 Linux - Filter a text from a specific file and append the output to another file Linux 从一台linux机器到另一台linux机器的远程文件传输 - Remote File Transfer from one linux machine to another linux machine 在 C 中将内容从一个文件复制到另一个文件 - Copy content from one file to another in C 在Linux中合​​并两个命令并将其附加到另一个文件 - Combine two commands in linux and append it to another file 在Linux中将一个文件的值替换为另一文件的值 - Replace value from one file with value from another file in linux 如何从1个txt文件中提取值并附加到另一个文件中? - How to take value from 1 txt file and append to another one? 从一个文件复制包含word的行到linux中的另一个文件 - copy lines containing word from one file to another file in linux
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM