如何将一个文件中的行附加到另一个文件的每一行的末尾?文件、末尾、如何将

2023-09-08 08:44:28 作者:性情古怪无人爱

假设我有两个文件:

猫狗狒狒

猫科动物犬类灵长类动物哪些文件属于某一vb工程中的文件

我想在添加空格后将一个文件中的行附加到另一个文件的末尾.我知道一种在 bash 中使用 for 循环来做到这一点的方法,但我认为有一个命令可以做到这一点,我就是不记得了.

输出应如下所示:

猫科动物犬类狒狒灵长类动物

解决方案

paste --delimiter=' ' file1 file2

注意:结果将被写入标准输出.如果要将结果存储在文件中,请使用重定向运算符:

粘贴 --delimiter=' ' file1 file2 >输出文件

运行 man paste 以获取有关该命令的更多信息.

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.

The output should look like:

cat feline
dog canine
baboon primate

解决方案

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 paste for more information about the command.