| # Check if the target_path is provided | |
| if [ -z "$1" ]; then | |
| echo "Error: target_path is not provided." | |
| exit 1 | |
| fi | |
| # Check if the user requested help | |
| if [ "$1" == "--help" ]; then | |
| echo "Usage: $0 -t target_path" | |
| echo " -t target_path The path to extract the .tar.gz files to." | |
| exit 0 | |
| fi | |
| # Set the target path | |
| target_path=$1 | |
| # Loop through all .tar.gz files in the current directory | |
| for file in *.tar.gz; do | |
| # Check if the file name matches the first pattern | |
| if [[ $file =~ ^training_dataset_division_.*\.tar\.gz$ ]]; then | |
| # Extract the file to the target path | |
| echo "extract $file into $target_path" | |
| tar -xf "$file" -C "$target_path" | |
| # Check if the file name matches the second pattern | |
| elif [[ $file =~ ^training_dataset_([-a-zA-Z0-9.]+)_division_.*\.tar\.gz$ ]]; then | |
| # Extract the file to a subdirectory named after the first capture group | |
| target_discipline_path=$target_path/${BASH_REMATCH[1]} | |
| mkdir -p $target_discipline_path | |
| echo "extract $file into $target_discipline_path" | |
| tar -xf "$file" -C $target_discipline_path | |
| else | |
| # Handle files that don't match either pattern | |
| echo "Skipping file: $file" | |
| fi | |
| done | |
| # Print a message to indicate that the extraction is complete | |
| echo "All .tar.gz files have been extracted." |