2017-01-24 56 views
0

我有多個命令,我希望以列的形式輸出每個命令的輸出。將不同命令的輸出並行排列成列

這裏是命令輸出I有:

echo "Batch 1 list" >> out.txt 
ssh -T [email protected] "echo 'DIS CLUSQMGR(*)'|runmqsc" |awk -F'[()]' '{print $2}' >> out.txt 
echo "===============================================================">> out.txt 
echo "Batch 2 list" >> out.txt 
ssh -T [email protected] "echo 'DIS CLUSQMGR(*)'|runmqsc" |awk -F'[()]' '{print $2}' >> out.txt 
echo "===============================================================">> out.txt 
echo "Batch 3 list">> out.txt 
ssh -T [email protected] "echo 'DIS CLUSQMGR(*)'|runmqsc" | awk -F'[()]' '{print $2}' >> out.txt 
echo "===============================================================">> out.txt 

這裏是輸出:

Batch list 
F111 
F211 
F311 
F411 
F511 
F9P1 
F9P4 
F9P6 
F9P7 
FA11 

=============================================================== 
Batch 2 list 
A111 
B211 
V311 
F411 
B511 
B9P1 
NA11 
FB11 
CD11 

=============================================================== 
batch 2 list 
C111 
C211 
R311 
Y411 
E511 
B9P1 
EA11 
AB11 
ND11 

我希望看到這種格式輸出:

Batch 1 list(count) Batch 2 list(count) Batch 3 list(count) 
F111     A111    C111 
F211     B211    C211 
F311     V311    R311 
F411     F411    Y411 
F511     B511    E511 
F9P1     B9P1    B9P1 
F9P4     NA11    EA11 
F9P6     FB11    AB11 
F9P7     CD11    ND11 
FA11 

計數是該列中的條目數。

回答

2

提取結果到單獨的文件,然後使用paste命令橫向定製在一起:

paste out1 out2 out3 > out.formatted 

這是輸出你會得到:

Batch list Batch 2 list batch 2 list 
F111 A111 C111 
F211 B211 C211 
F311 V311 R311 
F411 F411 Y411 
F511 B511 E511 
F9P1 B9P1 B9P1 
F9P4 NA11 EA11 
F9P6 FB11 AB11 
F9P7 CD11 ND11 
FA11 

獲取數是一個小棘手。而不是把標題中開始的,加上他們,而粘貼,就像這樣:

export count1=$(grep -c '^' out1) # need to export so that it is available to `cat`s below which run in subshells 
export count2=$(grep -c '^' out2) 
export count3=$(grep -c '^' out3) 
paste <(cat - <<< "Batch list ($count1)" out1) <(cat - <<< "Batch list ($count2)" out2) <(cat - <<< "Batch list ($count3)" out3) > out.formatted 
  • cat - - >確保貓從標準從這裏串<<<未來以及文件
+1

輸出不乾淨或未對齊到彩色。我用列-t來格式化,我可以使用它。謝謝 – MO12

0

更好地獲得分離文件中的每個輸出並將它們合併爲1

paste out1.log out2.log out3.log|expand --tabs=1>final_out.log