如何交织两个文本文件的行 [英] How to interleave lines from two text files

查看:124
本文介绍了如何交织两个文本文件的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是最简单/最快的方式来交错两个(或更多)文本文件的行?示例:

What's the easiest/quickest way to interleave the lines of two (or more) text files? Example:

文件1:

line1.1
line1.2
line1.3

文件2:

line2.1
line2.2
line2.3

交错:

line1.1
line2.1
line1.2
line2.2
line1.3
line2.3

确实很容易写一个小的Perl脚本,打开它们,并完成任务。但是我想知道是否可以使用更少的代码,也许使用Unix工具的单线程。

Sure it's easy to write a little Perl script that opens them both and does the task. But I was wondering if it's possible to get away with fewer code, maybe a one-liner using Unix tools?

推荐答案

paste -d '\n' file1 file2

这篇关于如何交织两个文本文件的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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