Я попытался сделать общее решение.Возможно, вам придется проверить его по нескольким сценариям.Но похоже, что он должен работать для большинства из них -
awk -F="|---" '
BEGIN{printf "mkdir -p /home/edwprod/dnp/"}
$1=="| |"{cnt++; if(count>0) count=0; if(cnt==1) printf "/{"$2",";else {printf $2","};next}
$1=="|"{count++; if(cnt>0) cnt=0;if(count<2) printf "{"$2","; else {printf $2","};next}END{if (NR==1) printf"\n"; else printf "}\n"}' FILENAME |
sed -e 's/,{/},/g' -e 's/{\([a-z0-9]\+\)}/\1/g' -e 's/,\//\//g' -e 's/,\(.[^,]*\),}$/,\1}/' -e 's/\(.*\)\/{\(.[^,}]*\)}$/\1\/\2}/' -e 's/\(.*[^{]\){\(.*[^,]\),$/\1\2/' -e 's/\(.*\)\/{\(.[^,}]*\),}$/\1\/{\2}/'
Тест:
[jaypal:~/Temp] cat file
|---archive
|---bin
| |---full_refresh
| |---to_be_deleted
|---in_dir
|---landing
| |---archive
|---log
|---tmp
[jaypal:~/Temp] awk -F="|---" '
BEGIN{printf "mkdir -p /home/edwprod/dnp/"}
$1=="| |"{cnt++; if(count>0) count=0; if(cnt==1) printf "/{"$2",";else {printf $2","};next}
$1=="|"{count++; if(cnt>0) cnt=0;if(count<2) printf "{"$2","; else {printf $2","};next}END{if (NR==1) printf"\n"; else printf "}\n"}' file |
sed -e 's/,{/},/g' -e 's/{\([a-z0-9]\+\)}/\1/g' -e 's/,\//\//g' -e 's/,\(.[^,]*\),}$/,\1}/' -e 's/\(.*\)\/{\(.[^,}]*\)}$/\1\/\2}/' -e 's/\(.*[^{]\){\(.*[^,]\),$/\1\2/' -e 's/\(.*\)\/{\(.[^,}]*\),}$/\1\/{\2}/'
mkdir -p /home/edwprod/dnp/{archive,bin/{full_refresh,to_be_deleted},in_dir,landing/archive,log,tmp}
[jaypal:~/Temp] cat file1
|---bin
|---file_dir
| |---old
|---in_dir
|---landing
| |---feed
|---log
|---out_dir
|---prc
| |---for
[jaypal:~/Temp] awk -F="|---" '
BEGIN{printf "mkdir -p /home/edwprod/dnp/"}
$1=="| |"{cnt++; if(count>0) count=0; if(cnt==1) printf "/{"$2",";else {printf $2","};next}
$1=="|"{count++; if(cnt>0) cnt=0;if(count<2) printf "{"$2","; else {printf $2","};next}END{if (NR==1) printf"\n"; else printf "}\n"}' file1 |
sed -e 's/,{/},/g' -e 's/{\([a-z0-9]\+\)}/\1/g' -e 's/,\//\//g' -e 's/,\(.[^,]*\),}$/,\1}/' -e 's/\(.*\)\/{\(.[^,}]*\)}$/\1\/\2}/' -e 's/\(.*[^{]\){\(.*[^,]\),$/\1\2/' -e 's/\(.*\)\/{\(.[^,}]*\),}$/\1\/{\2}/'
mkdir -p /home/edwprod/dnp/{bin,file_dir/old,in_dir,landing/feed,log,out_dir,prc/for}