DEV Community

Query Filter
Query Filter

Posted on

docker36

#!/bin/bash

ZIP_FILE="logs.zip"
OUTPUT_FILE="concatenated_logs.txt"

# Clear the output file if it exists
> "$OUTPUT_FILE"

# 1. List files in the zip (-Z1 gives a clean list of paths)
# 2. Use -r to handle backslashes or special characters in names
unzip -Z1 "$ZIP_FILE" | while read -r FILE_PATH; do

    # Skip directories (paths ending in /)
    if [[ "$FILE_PATH" == */ ]]; then
        continue
    fi

    echo "Processing: $FILE_PATH"

    # Add a clear, identifiable header to the output file
    echo -e "\n\n" >> "$OUTPUT_FILE"
    echo "================================================================================" >> "$OUTPUT_FILE"
    echo " SOURCE FILE: $FILE_PATH" >> "$OUTPUT_FILE"
    echo "================================================================================" >> "$OUTPUT_FILE"
    echo -e "\n" >> "$OUTPUT_FILE"

    # Extract the content of the specific file and append to the big file
    # -p (pipe) sends the file content to stdout, bypassing Windows path length limits
    unzip -p "$ZIP_FILE" "$FILE_PATH" >> "$OUTPUT_FILE"

done

echo "---"
echo "Done! All files concatenated into: $OUTPUT_FILE"
Enter fullscreen mode Exit fullscreen mode

Top comments (0)