你好,我目前正在試圖在Linux中創建一個腳本文件,其中輸入了oprgram的輸出並掃描它以查找有多少詞語存在的次數。爲了更清楚,我想掃描輸出並存儲變量,該輸出中存在多少個單詞。我對linux中的scripitin很陌生。我嘗試將輸出存儲在一個文件中,然後逐行掃描以找到這些單詞,但出於某種原因,我用來解析它的循環永遠不會結束。你可以幫我嗎?在shell中掃描程序的輸出
./program > buffer.txt
while read LINE
do
echo $LINE | grep word1 #when i use grep command the loop never ends
done <a.txt
編輯:在C等效程序將
char* word="word1"
while(/*parse all the lines at a text */)
{
fgetline("file_a",&buffer)
if(strcmp(buffer,word)==0)
strcpy(word1,"word") //continue the search with this
}
你寫buffer.txt和A.TXT閱讀。是對的嗎? – dogbane 2013-04-25 08:34:40
@dogbane是的,這是我想出的最好主意。但這個腳本永遠不會結束!它繼續無限。如果我使它回聲$行它工作正常 – JmRag 2013-04-25 08:46:43
我沒有看到這個循環的重點。爲什麼不簡單地使用'grep word1 a.txt'而不是循環?有些東西你沒有向我們展示。 – dogbane 2013-04-25 08:49:13