我有一个逐行填充流媒体的文件。我需要通过删除文件中最旧的记录来减少文件的音量。 我想计算行数,如果行数超过100,则删除最旧的行。但是我收到了以下错误:
./1.sh: line 18: syntax error near unexpected token `done'
./1.sh: line 18: `done'
这是我的代码:
#!/bin/bash
FILE="11.txt"
linenum=0
while true; do
#Count number of lines
linenum=`cat "$FILE" | wc -l`
while [ $linenum -gt 100 ] do
#Delete the head of file (oldest)
sed -i 1,1d "$FILE"
#Count number of lines
linenum=`cat "$FILE" | wc -l`
done
done
你能帮帮我吗?
答案 0 :(得分:3)
您需要换行符AVG({ FIXED [Weekday Flagging],[Hour]:
AVG([Volume])})
条件与;
之间的while
:
do
我还正确地缩进了代码,将子shell while [ $linenum -gt 100 ]; do
#Delete the head of file (oldest)
sed -i 1,1d "$FILE"
#Count number of lines
linenum=$(wc -l "$FILE")
done
符号更改为更现代的`...`
并删除了$(...)
的多余使用。
答案 1 :(得分:0)
你错过了下面一行的分号
while [ $linenum -gt 100 ] do
应该是
while [ $linenum -gt 100 ] ; do
希望这有帮助。