grep -v -f /tmp/pn.filter offset.txt > offset.txt.partial
cat offset.txt.partial offset.txt.new > offset.txt
+echo "Press enter to remove old data or ctrl+c to abort"
+read wait_for_enter
+
+in_pn=$( cat /tmp/pn.filter | tr '\n' ',' | sed 's/,$//' )
+last_alarm=$( echo "select max(time) from zc where pn in ( $in_pn ) and alarm_axis > 0" | psql -A -t zc )
+removed="removed_$( date +%Y_%m_%d )"
+echo "last alarm at $last_alarm"
+echo "create table $removed as select * from zc where pn in ( $in_pn ) and time <= '$last_alarm'" | psql zc
+echo "delete from zc where _id in ( select _id from $removed )" | psql zc