File size: 2,097 Bytes
80a8351
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/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."