linux - How to transform tree in text format with nesting levels designated by numbers -
i'd appreciate advice on how transform (preferably bash) text file, foobar.txt, stores information directory structure in following format:
1 qwe
2 rty
1 uio
1 asd
2 fgh
3 jkl
2 zxc
the first digit of every line designates nesting level (7 largest value). need create corresponding directory tree on disk. command «xargs -a foobar.txt mkdir -p» create tree, content of foobar.txt has like:
./qwe/rty
./uio
./asd/fgh/jkl
./asd/zxc
here's way awk. print desired directories:
awk '{dir[$1]=$2; for( in dir ) { if( i<=$1 ) { if( i==1 ) printf("."); printf("/%s", dir[i]); }} printf("\n"); }' text_file
and of course, can tack on mkdir after create them:
awk '{dir[$1]=$2; for( in dir ) { if( i<=$1 ) { if( i==1 ) printf("."); printf("/%s", dir[i]); }} printf("\n"); }' text_file | xargs mkdir -p
Comments
Post a Comment