#!/bin/bash # ================================================================= # Configuration # Modify these variables to match your environment. # ================================================================= # Prefix for the split files (e.g., abc_dataset_part_aa, abc_dataset_part_ab, etc.) FILE_PREFIX="abc_dataset_part_" # Name of the final merged .tar file MERGED_TAR_FILE="ABC_Dataset_full.tar" # Directory to extract files into EXTRACT_DIR="ABC_Dataset_extracted" # ================================================================= # Script Body # Do not modify below this line unless you know what you are doing. # ================================================================= # Exit immediately if a command exits with a non-zero status. set -e echo ">> 1. Verifying split files exist..." files=(${FILE_PREFIX}*) if [ ! -f "${files[0]}" ]; then echo "Error: Could not find split files starting with '${FILE_PREFIX}'." echo "Ensure this script is in the same directory as the split files and FILE_PREFIX is correct." exit 1 fi echo "Split files found. Starting merge." echo "" echo ">> 2. Merging split files..." # The wildcard (*) is automatically sorted alphabetically by the shell (aa, ab, ac...). cat ${FILE_PREFIX}* > ${MERGED_TAR_FILE} echo "Merge complete. Output file: ${MERGED_TAR_FILE}" echo "" echo ">> 3. Creating destination directory..." mkdir -p ${EXTRACT_DIR} echo "Directory ready: ${EXTRACT_DIR}" echo "" echo ">> 4. Extracting TAR archive..." # -x: extract, -v: verbose, -f: file, -C: change to directory tar -xvf ${MERGED_TAR_FILE} -C ${EXTRACT_DIR} echo "Extraction complete." echo "" echo "==========================================" echo "🎉 All tasks completed successfully!" echo "Data is available in the '${EXTRACT_DIR}' directory." echo "==========================================" # Optional: Uncomment the lines below to delete the original split parts and the merged .tar file after completion. # echo "" # echo ">> 5. Cleaning up source files..." # rm ${FILE_PREFIX}* # rm ${MERGED_TAR_FILE} # echo "Cleanup complete."