bash 如何将一个文件的行附加到另一个文件的每一行的末尾?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4358192/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I append lines from one file to the end of each line of another file?
提问by donatello
Suppose I have two files:
假设我有两个文件:
cat dog baboon
feline canine primate
I want to append the lines from one file at the end of another file after adding a space. I know a way to do this using a for loop in bash, but I think there is a single command that can do this sort of thing, and I just can't remember it.
添加空格后,我想将一个文件中的行附加到另一个文件的末尾。我知道一种在 bash 中使用 for 循环来执行此操作的方法,但我认为有一个命令可以执行此类操作,但我不记得了。
The output should look like:
输出应如下所示:
cat feline dog canine baboon primate
回答by Lekensteyn
paste --delimiter=' ' file1 file2
Note: the result will be written to stdout. If you want to store the result in a file, use a redirection operator:
注意:结果将写入标准输出。如果要将结果存储在文件中,请使用重定向运算符:
paste --delimiter=' ' file1 file2 > outputfile
Run man pastefor more information about the command.
运行man paste以获取有关该命令的更多信息。

