Upload extract.sh with huggingface_hub
Browse files- extract.sh +40 -0
extract.sh
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/bin/bash
|
2 |
+
|
3 |
+
# Check if the target_path is provided
|
4 |
+
if [ -z "$1" ]; then
|
5 |
+
echo "Error: target_path is not provided."
|
6 |
+
exit 1
|
7 |
+
fi
|
8 |
+
|
9 |
+
# Check if the user requested help
|
10 |
+
if [ "$1" == "--help" ]; then
|
11 |
+
echo "Usage: $0 -t target_path"
|
12 |
+
echo " -t target_path The path to extract the .tar.gz files to."
|
13 |
+
exit 0
|
14 |
+
fi
|
15 |
+
|
16 |
+
# Set the target path
|
17 |
+
target_path=$1
|
18 |
+
|
19 |
+
# Loop through all .tar.gz files in the current directory
|
20 |
+
for file in *.tar.gz; do
|
21 |
+
# Check if the file name matches the first pattern
|
22 |
+
if [[ $file =~ ^training_dataset_division_.*\.tar\.gz$ ]]; then
|
23 |
+
# Extract the file to the target path
|
24 |
+
echo "extract $file into $target_path"
|
25 |
+
tar -xf "$file" -C "$target_path"
|
26 |
+
# Check if the file name matches the second pattern
|
27 |
+
elif [[ $file =~ ^training_dataset_([-a-zA-Z0-9.]+)_division_.*\.tar\.gz$ ]]; then
|
28 |
+
# Extract the file to a subdirectory named after the first capture group
|
29 |
+
target_discipline_path=$target_path/${BASH_REMATCH[1]}
|
30 |
+
mkdir -p $target_discipline_path
|
31 |
+
echo "extract $file into $target_discipline_path"
|
32 |
+
tar -xf "$file" -C $target_discipline_path
|
33 |
+
else
|
34 |
+
# Handle files that don't match either pattern
|
35 |
+
echo "Skipping file: $file"
|
36 |
+
fi
|
37 |
+
done
|
38 |
+
|
39 |
+
# Print a message to indicate that the extraction is complete
|
40 |
+
echo "All .tar.gz files have been extracted."
|