Q:

script to clear file contents using sed

I am trying to delete few lines (that are 1 day older) from a file using sed but it gives an error while executing the script. 
What could be causing the above error? Could anyone please help?
~]# ./test.sh

Jan 20
36
sed: -e expression #1, char 3: unexpected `,'

Here is the script:
month=$(date --date="1 day ago" | cut -d " " -f2,3)

echo $month

line=$(grep -n "$month" test.log | cut -d : -f 1 | tail -1)

echo $line

if [ ! -z "$line" -a "$line" != " " ];

then

sed -i '1,"$line"d' test.log

#echo "sed -i '1,"$line"d' test.log"

else

exit

fi

A:

I suggest you to change the sed line as,
sed -i '1,'"$line"'d' test.log
          ^       ^        
          |       |

