Linux

將螢幕輸出堆疊成列以利用螢幕寬度並避免滾動

  • February 22, 2017

我經常gridengine在我們的 HPC 集群上使用 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)

當然,最好指定任意數量的列。

我發現的唯一類似的問題/答案是這個,但我希望有一種更簡單的方法可以在一行中使用管道而不是腳本文件來做到這一點。

我剛剛找到了解決方案;管它到pr.

對於範例數據文件:

cat data1.txt | pr -2 -l 60

對於gridengine的qstat

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

-2標誌僅指定 2 列。您可以調整寬度參數-w以更好地適應原始列寬,調整長度參數-l以調整輸出被分割的頁數。對於更長的輸出,您可能需要更高的-l值。

引用自:https://unix.stackexchange.com/questions/346862