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

标签 linux bash list unix command

我想用分隔符“-”合并不同的列表。

第一个列表有 2 个词

  $ cat first
    one
    who

第二个列表有 10000 个单词

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

我想要两个列表合并,相同...

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

最佳答案

<德尔> Paste应该做的伎俩。

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 -d - file1 file2

编辑:

我刚刚看到您的两个文件的长度不同。不幸的是粘贴不是 帮助解决这类问题。但是你当然可以使用这样的东西:

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

关于linux - 如何使用 bash 粘贴来自不同文件的列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44789346/

相关文章:

具有奇怪顺序的 CSS 菜单

vb.net - 如何使用 Linq 从 List(Of T) 中获取不同值

linux - 无法在 Oracle Linux 中启动 docker 引擎

regex - sed 正则表达式无法按预期工作。管道和文件不同

database - 在 bash 脚本中使用通配符

bash - 如何在文件中搜索多个字符串

bash - 在 Debian 7 上运行 bash 脚本时选项无效

list - 从 lisp 中的列表中评估函数

python - 无法从 putty 运行 .py 文件,语法错误 : word unexpected (expecting ")")

linux - 连接到安装了单声道的 Informix DB 时出现 ODBC 错误