
for f in wrccdc-*.pcap*; do
    # Use stat to get full modification time
    # %Y = epoch seconds, %N = nanoseconds (GNU stat)
    read epoch ns <<< "$(stat -c '%Y %N' "$f")"
    ms=${ns:0:3} # first 3 digits = milliseconds

    # Format date/time
    datetime=$(date -d @"$epoch" '+%Y-%m-%d.%H%M%S')

    key="$datetime"

    # Handle duplicates
    count=${seen[$key]:-0}
    seen[$key]=$((count + 1))

    if (( count > 0 )); then
        printf -v inc "%04d" $count
        newfile="./dest/wrccdc2026-inv2.${datetime}${ms}${inc}.pcap"
    else
        inc="00"
        newfile="./dest/wrccdc2026-inv2.${datetime}${ms}${inc}.pcap"
    fi

    echo "Renaming: $f -> $newfile"
done

