我编写了一个小脚本来计算特定文件中日志的出现次数(以兆字节为单位),下面是我的代码
#!/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