简体   繁体   English

如何使用 bash 粘贴来自不同文件的列?

[英]How can i paste columns from separate files using bash?

I want to merge different lists with delimiter "-".我想用分隔符“-”合并不同的列表。

first list has 2 words第一个列表有 2 个词

  $ cat first
    one
    who

second list has 10000 words第二个列表有 10000 个单词

$ cat second
languages
more
simple
advanced
home
expert
......
......
test
nope

i want two list merge, same ...我想要两个列表合并,相同...

$cat merge-list
one-languages
one-more
....
....
who-more
....
who-test
who-nope
....

Paste should do the trick.粘贴应该可以解决问题。

paste is a Unix command line utility which is used to join files horizontally (parallel merging) by outputting lines consisting of the sequentially corresponding lines of each file specified, separated by tabs, to the standard output. paste 是一个 Unix 命令行实用程序,用于水平连接文件(并行合并),方法是将指定的每个文件的顺序对应行组成的行输出到标准输出,以制表符分隔。

Example例子

paste -d - file1 file2

EDIT:编辑:

I just saw that your two files have different length.我刚刚看到你的两个文件有不同的长度。 Unfortunately paste is not helping with these kinds of problems.不幸的是,粘贴对解决此类问题没有帮助。 But you could of course use something like this:但是你当然可以使用这样的东西:

for i in `cat file1`; do 
    for j in `cat file2`; do 
        echo $i-$j
    done
done

暂无
暂无

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

相关问题 如何从不同的文本文件中复制字符串以在单独的列中并排显示到 Bash 中的第三个文件中 - How to copy strings from different text files to show side by side, in separate columns, into a third file in Bash 如何仅使用键盘将bash复制并粘贴到vim,反之亦然? - How do I copy and paste from bash to vim and vice-versa using only the keyboard? 如何使用BASH将tar命令中的文件读取到数组中? - How can I read the files from a tar command into an array using BASH? 使用bash脚本,如何修剪包含文件的文件夹中的最后12个字符 - Using bash scripting how can I trim the last 12 characters from a folder containing files 使用du的输出,如何在bash中显示对应于给定大小以上或以下文件的行? - Using output from du, how can I display lines that correspond to files above or below a given size in bash? 如何使用bash脚本将一行中的某些重复模式分成多行? - How can I separate some repeated patterns in a row into multiple rows using bash script? 如何从多个文件中提取一列,并将这些列粘贴到一个文件中? - How to extract one column from multiple files, and paste those columns into one file? 使用bash,如何删除特定目录中所有文件的扩展名? - Using bash, how can I remove the extensions of all files in a specific directory? 如何在使用bash更改名称和扩展名的同时将多个文件移动到目录中? - How can I move multiple files to a directory while changing their names and extensions using bash? 如何使用bash在命令行中计算日期范围内特定文件的数量? - How can I count the number of specific files within a date range on the command line using bash?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM