2012-12-05 35 views
0

我是新手,因此這可能看起來像一個愚蠢的問題,但我不能讓這個代碼工作。看起來,grep正在尋找變量名稱而不是它的值。感謝任何幫助appriciated。grep將不能在bash腳本中工作

if [ "$file" == "osi_OpenInterest" ] 
    then 
     count=`cat timestamps.txt | grep "${file}" | grep "${currdate}" | grep "07:" | grep "AM" | wc -l` 
     if [ $count -eq 0 ]; 
     then 
      echo "$file not found" | mail -s "RetrieverB Missing File" "$email" 
     fi 
    fi 
+0

以目前的形式回答這個問題是不可能的。哪部分你有問題? 'echo「X $ {file} X $ {currdate} X」;'拿出具體的例子,沒有變量,時間戳文件的內容和期望的輸出。 –

+0

timestamps.txt包含:** 12-04-2012 07:30 AM 15028622 osi_OpenInterest ** 這就是grep語句的預期輸出,所以count應該是1.從我可以告訴greps似乎在執行搜索對於$ {file}而不是** osi_OpenInterest **同樣的事情與$ {currdate}應該在尋找** 12-04-2012 **而不是「$ {currdate} – user1877532

+1

我要求您驗證您的內容變量。不要拿出瘋狂的假設(「它正在尋找$ {currdate}」) –

回答

1

currdate12-04-12。您的文件包含日期格式不同,12-04-2012,因此沒有匹配。

+0

謝謝。我完全忽視了我一直盯着這個計劃好幾個小時。它有20個if語句,如果聲明的是currdate而不是date,那麼它有相同的問題+%m-%d-%Y我用了日期+%m-%d-%y – user1877532