#!/bin/bash

# File containing paths and filenames
order_file="order.queue"

# Check if the file exists
if [ ! -f "$order_file" ]; then
    echo "File not found: $order_file"
    exit 1
fi

temp_file=$(mktemp)

# Loop through each line in the order file
while IFS= read -r line; do
    # Extract path and filename from the line
    path=$(dirname "$line")
    filename=$(basename "$line" .log)
    logorder="${path}/${filename}_order.log"

    # Check if the corresponding file exists
    if [ -f "$logorder" ]; then
        # Remove the line if the file exists
        continue
    else
        # Write the line to the temporary file
        echo "$line" >> "$temp_file"
    fi
done < "$order_file"

# Replace the original file with the temporary file
mv "$temp_file" "$order_file"

# Remove temporary file
rm -f "$temp_file"


cat "$order_file"