+# Detecting Session-Id values:
+grep ^sessionid= $RESULTS_DIR/*.metadata 2>/dev/null | cut -d= -f2- | sort -u > $RESULTS_DIR/session-ids
+if [ -s $RESULTS_DIR/session-ids ]
+then
+ count=0
+ while read -r line; do count=$((count+1)) ; echo "Detected Session-Id $count: $line"; done < $RESULTS_DIR/session-ids
+ rm $RESULTS_DIR/session-ids
+fi
+
+# Purge frames with Session-Id not wanted:
+if [ -n "$SIDS_FILE" ]
+then
+ grep -l -w -f $SIDS_FILE $RESULTS_DIR/*metadata > $RESULTS_DIR/.wanted
+ grep -l ^sessionid $RESULTS_DIR/*metadata > $RESULTS_DIR/.all
+ for file in `grep -vf $RESULTS_DIR/.wanted $RESULTS_DIR/.all`
+ do
+ frm=$(basename $file | cut -d\. -f1)
+ sid=$(grep ^sessionid= $file | cut -d= -f2-)
+ echo "Purge results for frame $frm (Session-Id: '$sid') ..."
+ rm $RESULTS_DIR/${frm}.*
+ done
+ rm $RESULTS_DIR/.wanted $RESULTS_DIR/.all
+fi