Skip to main content
2 of 4
added 218 characters in body
mikeserv
  • 59.4k
  • 10
  • 122
  • 242
cd /path/to/dir
(   set -- *\ *
    printf 'd="%s" ; mkdir ./"${d%.doc}"\n' "$@"
) | . /dev/stdin

You can set a subshell's parameters with shell globs and then feed a pipe with printf, and . source the pipe as a script.

And if you want to move the files in each directory:

cd /path/to/dir
(   set -- *\ *
    printf 'f="%s" ; d="${f%.doc}"
        mkdir ./"$d" ; echo "mv ./\"$f\" ./\"$d\"/\"$f\""\n' "$@"
) | . /dev/stdin

Note: I've intentionally hamstrung the above with echo because I want you test the output before you dive-in.

mikeserv
  • 59.4k
  • 10
  • 122
  • 242