2011-10-21 66 views
0

我想在Solaris上使用tee命令將1個命令的輸出路由到2個不同的每個包含多個語句的不同的steamed。這是我編碼的片段,但不起作用。此迭代會引發有關意外文件結尾的錯誤。如果我將>更改爲|它會在意外令牌附近引發錯誤語法錯誤。開球到2塊代碼?

todaydir=/some/path 
baselen=${#todaydir} 

grep sometext $todaydir/somefiles* 

while read iline 
tee 
>(
# this is the first block 
do ojob=${iline:$baselen+1:8} 
    echo 'some text here' $ojob 
done > firstoutfile 
) 
>(
# this is the 2nd block 
do ojob=${iline:$baselen+1:8} 
    echo 'ls -l '$todaydir'/'$ojob'*' 
done > secondoutfile 
) 

建議?

回答

1

該「while」應該開始(和結束)裏面每個>(...)替代,而不是外部。因此,我相信你想要的是:

todaydir=/some/path 
baselen=${#todaydir} 

grep sometext $todaydir/somefiles* | tee >(
    # this is the first block 
    while read iline 
    do ojob=${iline:$baselen+1:8} 
     echo 'some text here' $ojob 
    done > firstoutfile 
) >(
    # this is the 2nd block 
    while read iline 
    do ojob=${iline:$baselen+1:8} 
     echo 'ls -l '$todaydir'/'$ojob'*' 
    done > secondoutfile 
) 
+0

工作很好,謝謝。 – JimR

0

我不認爲tee命令會這樣做。 tee命令會將stdin寫入一個或多個文件,並將其吐出到標準輸出。另外我不確定shell是否可以像你嘗試的那樣在命令管道中分離出兩個子進程。你最好使用像Perl這樣的東西來分離幾個子進程,併爲每個子進程寫stdin。