I have a file which filled in streaming way line by line. I need to decrease the volume of the file by deleting the oldest record in it. I would like to count the number of lines and if the number of lines exceed than 100 then delete the oldest lines. However I got the following error:
./1.sh: line 18: syntax error near unexpected token `done'
./1.sh: line 18: `done'
Here is my code:
#!/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
Can you please help me?
sed -i(effectively) makes a copy of the input file, then replaces the original with the modified copy. If the original is written to whilesedis working on the copy, those changes are lost.