并排显示两个文件 [英] Display two files side by side
问题描述
如何在 shell
给定 one.txt
和 two.txt
:
$ cat one.txt
apple
pear
longer line than the last two
last line
$ cat two.txt
The quick brown fox..
foo
bar
linux
skipped a line
显示:
apple The quick brown fox..
pear foo
longer line than the last two bar
last line linux
skipped a line
粘贴one.txt two.txt
因为它只是在第1列和第2列之间打印一个标签。我知道如何使用emacs和vim,但希望输出显示到stdout管道系统。
paste one.txt two.txt
almost does the trick but doesn't align the columns nicely as it just prints one tab between column 1 and 2. I know how to this with emacs and vim but want the output displayed to stdout for piping ect.
我想出的解决方案使用 sdiff
然后管道sed以删除输出 sdiff
补充说。
The solution I came up with uses sdiff
and then pipes to sed to remove the output sdiff
adds.
sdiff one.txt two.txt | sed -r'/ [<> || /// s /(\ t){3} //'
我可以创建一个函数,并将其粘贴在我的 .bashrc
,但肯定有一个命令已经存在(或潜在的一个更清洁解决方案) / p>
I could create a function and stick it in my .bashrc
but surely a command for this exists already (or a cleaner solution potentially)?
推荐答案
您可以使用 pr
$ c> -m 标志合并文件,每列一个, -t
可省略标题,例如
You can use pr
to do this, using the -m
flag to merge the files, one per column, and -t
to omit headers, eg.
pr -m -t one.txt two.txt
输出:
apple The quick brown fox..
pear foo
longer line than the last two bar
last line linux
skipped a line
这篇关于并排显示两个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!