2017-02-14 21 views
1

當我做svn up時,我得到的平均輸出量爲100行。另外還有X-teen外部體,總共可以更新約30秒(它們每隔2-3s就會一個接一個地彈出)。如何在運行時着色shell輸出

我想着色(也許是轉換)這個輸出,以便我可以更清楚地看到它。

我知道我可以使用sed來做到這一點,但它需要一個討厭格式的正則表達式 - 大量轉義字符。
perl另一方面需要更清潔的正則表達式,但它在打印輸出之前等待整個輸入 - 我得到了30秒沒有和BAM整個輸出立即出現。

up.sh

#!/bin/bash 

svn up [email protected] \ 
    | grep -vE "^\s*$|revision" \ 
    | ${arhbin}/coloring/svn.sh \ 

$ {} arhbin /coloring/color_definitions.sh

#!/bin/bash 
source ${arhbin}/coloring/color_definitions.sh 

cat \ 
    | perl -pe 's/(^ *A.*$)/'$GREEN'\1'$NORMAL'/igs' \ 
    | perl -pe 's/(^ *D.*$)/'$RED'\1'$NORMAL'/igs' \ 
    | perl -pe 's/(^ *C.*$)/'$RED_BG'\1'$NORMAL'/igs' \ 
    | perl -pe 's/(^ *[?].*$)/'$BLUE'\1'$NORMAL'/igs' \ 
    | perl -pe 's/(^ *G.*$)/'$BLUE'\1'$NORMAL'/igs' \ 

我怎樣才能顏色的命令在運行時使用Perl/Python的正則表達式一樣的輸出?

+0

你在Linux上嗎? – hek2mgl

+1

我會首先確定沒有任何東西被緩衝。 – simbabque

+0

@ hek2mgl是的,紅色帽子要精確 –

回答

1

在Linux上,您可以使用stdbuf來調整io緩衝。像這樣:

stdbuf -oL svn up "[email protected]" | perl ... 
+1

太棒了,'stdbuf'正是我需要的,謝謝。 這是實際的工作解決方案: 'svn up $ @ | stdbuf -oL grep -vE「^ \ s * $ | revision」(...)' –

+0

很高興看到它幫助你! – hek2mgl