将屏幕输出堆叠到列中以利用屏幕宽度并避免滚动

将屏幕输出堆叠到列中以利用屏幕宽度并避免滚动

我经常gridengine在 HPC 集群上使用 's qstat 命令,但由于集群上正在运行许多作业,因此输出太长,无法显示在我的屏幕上,因此我最终需要进行大量滚动才能查看输出的上半部分。我的终端有足够的空间容纳两列,因此如果它们的输出可以流入列并并排显示,那就太好了。

使用简单数据文件的示例: 显然,这对于任何屏幕输出都应该是通用的,因此这里用一个更简单的例子来说明:

我的文件data1.txt包含 100 行"This is a test".

>> cat data1.txt
This is a test
This is a test
This is a test
This is a test
This is a test
This is a test
This is a test
This is a test
This is a test
This is a test
This is a test
This is a test
This is a test
This is a test
This is a test
This is a test
This is a test
This is a test
This is a test
This is a test
(etc. until 100th line)
>> 

期望的输出:

>> cat data1.txt | something | something_else -n 2
This is a test  This is a test
This is a test  This is a test
This is a test  This is a test
This is a test  This is a test
This is a test  This is a test
This is a test  This is a test
This is a test  This is a test
This is a test  This is a test
This is a test  This is a test
This is a test  This is a test
This is a test  This is a test
This is a test  This is a test
This is a test  This is a test
This is a test  This is a test
This is a test  This is a test
This is a test  This is a test
This is a test  This is a test
This is a test  This is a test
This is a test  This is a test
This is a test  This is a test
This is a test  This is a test
This is a test  This is a test
This is a test  This is a test
This is a test  This is a test
This is a test  This is a test
This is a test  This is a test
This is a test  This is a test
(etc. until 50 rows)

当然,最好指定任意数量的列。

我发现的唯一类似的问题/答案是这个但我希望有一种更简单的方法可以使用管道而不是脚本文件在一行中完成此操作。

答案1

我刚刚找到了一个解决方案;通过管道将其传输到pr.

对于示例数据文件:

cat data1.txt | pr -2 -l 60

对于 Gridengine 来说qstat

qstat -f -u "*" | pr -2 -w 270 -l 130

-2标志仅指定 2 列。您可以调整宽度参数-w以更好地适应原始柱状宽度,并调整长度参数-l以调整输出分割的页数。对于更长的输出,您可能需要更高的-l值。

相关内容