作者:凹凸曼00威威_694 | 来源:互联网 | 2023-05-27 12:06
Howcan2unsortedtextfilesofdifferentlengthsbedisplaysidebyside(incolumns)inashell
How can 2 unsorted text files of different lengths be display side by side (in columns) in a shell
如何在shell中并排显示两个不同长度的未排序文本文件(以列表示)
Given one.txt
and two.txt
:
给一个。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
Display:
显示:
apple The quick brown fox..
pear foo
longer line than the last two bar
last line linux
skipped a line
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.
粘贴一个。三两个。txt几乎可以做到这一点,但它并没有很好地对齐列,因为它只是在列1和列2之间打印一个选项卡。我知道如何使用emacs和vim来实现这一点,但我希望输出显示为stdout以便进行管道优化。
The solution I came up with uses sdiff
and then pipes to sed to remove the output sdiff
adds.
我提出的解决方案使用sdiff,然后通过管道将输出sdiff添加到sed,以删除输出sdiff。
sdiff one.txt two.txt | sed -r 's/[<>|]//;s/(\t){3}//'
sdiff。三两个。txt | sed -r 's/[<>|]/;s/(\t){3}/ '
I could create a function and stick it in my .bashrc
but surely a command for this exists already (or a cleaner solution potentially)?
我可以创建一个函数,并将其粘贴到.bashrc中,但是对于它来说,一个命令肯定已经存在(或者可能是一个更干净的解决方案)?
9 个解决方案