我編寫了一個小腳本來計算特定檔案中日誌的出現次數(以兆位元組為單位),以下是我的程式碼
#!/bin/sh
count=1
while read line
do
found=$( grep M $line )
if [ "$found" ]; then
echo $count")" $line >> filesave.txt
fi
count=$((count+1))
done < log1.txt
但我收到類似 ./count.sh ./count.sh: 在第 10 行語法錯誤: `found=$' 意外的錯誤
答案1
grep M log1.txt |
cat -n |
sed 's/^[[:space:]]*\([0-9]\+\)[[:space:]]*/\1\)/' >> filesave.txt
sed
如果您對以下輸出感到滿意,則該腳本是可選的cat -n
grep M log1.txt | cat -n >> filesave.txt