I have a file with following strings and need to assign path to folder with digits into variable:
/tmp/gfh/000000004802803/blablabla/EngID_Consolidation.zip
/tmp/vcbn/000000005395825/blablabla/172_6578-DUMP_NOMServer.zip
/tmp/one3/435876dfhg/000000004017051/5.zip
/tmp/one3/dsfkgjh/dsjfhgfd/000000004617319/Sybase.zip
E.g. I need to assign in variable: /tmp/gfh/000000004802803/
Digits and path always different. As a first step I've assigned into variable folder with digits using regex:
zip_folder_name0=$(grep -E -o "/([0]{5}[0-9]{10})/" <<< $zip_path)
zip_folder_name=${zip_folder_name0#"/"}
zip_folder_name=${zip_folder_name%"/"}
echo $zip_folder_name
Which return 000000004802803 How to assign into another variable all path to folder from the root ? I think it can be done by regex, from the start of the string to variable $zip_folder_name. Is this possile? Or maybe there is another way?
UPD1 Just forgot to mention, that after folder with digits can be another folder, e.g. /tmp/gfh/000000004802803/blablabla/EngID_Consolidation.zip And I need exactly /tmp/gfh/000000004802803/ into variable.
/tmp/gfh/ijk/012345/myzip.zipor/tmp/gfh/0123/4567/myzip.zip?)