Created
May 29, 2019 05:22
-
-
Save ratulbasak/5e4b877e89aceb81c1d2abf5f73dd15b to your computer and use it in GitHub Desktop.
Unzipping .gz files recursively in a directory...
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
red=$'\e[1;31m' | |
grn=$'\e[1;32m' | |
yel=$'\e[1;33m' | |
blu=$'\e[1;34m' | |
mag=$'\e[1;35m' | |
cyn=$'\e[1;36m' | |
end=$'\e[0m' | |
base_data_path=$PWD'/April_2019/*' | |
output_path=$PWD'/output' | |
WORKDIR=$PWD | |
unzip_folder(){ | |
printf "%s\n" "${red}Unzipping...${end}" | |
for dir in $base_data_path; do | |
echo "$(basename "$dir")" | |
for file in $dir/*.gz; do | |
STEM=$(basename "${file}" .gz) | |
echo 'path to file '$base_data_path/$filex | |
echo "$output_path/$STEM" | |
gunzip -c < "$file" > "$output_path/$STEM" -f | |
done | |
done | |
printf "%s\n" "${blu}Unzipping Completed...${end}\n${red}OUTPUT PATH:${end} ${grn}$output_path${end}" | |
} | |
if [ -d $output_path ]; | |
then | |
rm -rf $output_path | |
mkdir $output_path | |
unzip_folder | |
else | |
echo "$output_path" | |
mkdir $output_path | |
unzip_folder | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment