如何将一个文件的行附加到另一个文件的每一行的末尾? [英] How do I append lines from one file to the end of each line of another file?

查看:35
本文介绍了如何将一个文件的行附加到另一个文件的每一行的末尾?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有两个文件:

<前>猫狗狒狒

<前>猫科动物犬类灵长类动物

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

输出应如下所示:

<前>猫科动物狗狒狒灵长类动物

解决方案

paste --delimiter=' ' file1 file2

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

paste --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.

这篇关于如何将一个文件的行附加到另一个文件的每一行的末尾?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆