seblavoie
9/28/2012 - 7:21 PM

Plain text directory structure creation in bash

Plain text directory structure creation in bash

folder-01
| subfolder-01
| subfolder-02
| | deeper-subfolder-01
| | deeper-subfolder-02
folder-02
#!/bin/sed -f

s/^//
x
G
: loop
s:\([^/]*\)/*\(.*\n\)\([^|]*\)|\s:\2\3\1/:
t loop

s/.*\n//
s:/*$::
h
# Creates folder structure from plain text.
# Based on this stackoverflow question and answer http://stackoverflow.com/questions/12642260/better-bash-script-to-create-directory-structure
mkdirs($file) {
  sed -f mkdirs.sed $file | xargs mkdir -p
}