Hello All,
For the past year I've been using the following script to compile files into folders using Terminal. I deal with thousands of files so it helps out a lot. Pretty much if I have the following files:
filename1.mp4
filename1.txt
filename1.vtt
filename2.mp4
filename2.txt
filename2.vtt
It will create folders with those files compiled inside of them such as:
filename1
filename1.mp4
filename1.txt
filename1.vtt
filename2
filename2.mp4
filename2.txt
filename2.vtt
The code was working last week, but today it's giving me errors.
Here is the code:
find -iname \*asx -or -iname \*clean.txt -or -iname \*dvdIt.txt -or -iname \*.qt.\* -or -iname \*.rt\* -or -iname \*scc -or -iname \*sdf -or -iname \*smi -or -iname \*srt -or -iname \*stl | xargs rm -rf
find . -type f -print |
while read -r pathname; do
filename=${pathname##*/}
case "$filename" in
*_hi* | *_med* | *_lo*)
# strip off last underscore and following chars
new_dirname=${filename%_*}*
;;
*)
# strip off first dot and following chars
new_dirname=${filename%%.*}*
;;
esac
mkdir -p "../$new_dirname"
mv "$pathname" "../$new_dirname/$filename"
done
Here are the errors that I am getting:
dmuncy-m1:~ dmuncy$ cd /Users/dmuncy/Desktop/bin/source
dmuncy-m1:source dmuncy$ find -iname \*asx -or -iname \*clean.txt -or -iname \*dvdIt.txt -or -iname \*.qt.\* -or -iname \*.rt\* -or -iname \*scc -or -iname \*sdf -or -iname \*smi -or -iname \*srt -or -iname \*stl | xargs rm -rf
find: illegal option -- i
usage: find [-H | -L | -P] [-EXdsx] [-f path] path ... [expression]
find [-H | -L | -P] [-EXdsx] -f path [path ...] [expression]
dmuncy-m1:source dmuncy$ find . -type f -print |
> while read -r pathname; do
> * * filename=${pathname##*/}
> * * case "$filename" in
> * * * * *_hi* | *_med* | *_lo*)
-bash: syntax error near unexpected token `)'
dmuncy-m1:source dmuncy$ * * * * * * # strip off last underscore and following chars
-bash: *: command not found
dmuncy-m1:source dmuncy$ * * * * * * new_dirname=${filename%_*}*
-bash: *: command not found
dmuncy-m1:source dmuncy$ * * * * * * ;;
-bash: syntax error near unexpected token `;;'
dmuncy-m1:source dmuncy$ * * * * *)
-bash: syntax error near unexpected token `)'
dmuncy-m1:source dmuncy$ * * * * * * # strip off first dot and following chars
-bash: *: command not found
dmuncy-m1:source dmuncy$ * * * * * * new_dirname=${filename%%.*}*
-bash: *: command not found
dmuncy-m1:source dmuncy$ * * * * * * ;;
-bash: syntax error near unexpected token `;;'
dmuncy-m1:source dmuncy$ * * esac
-bash: *: command not found
dmuncy-m1:source dmuncy$ * * mkdir -p "../$new_dirname"
-bash: *: command not found
dmuncy-m1:source dmuncy$ * * mv "$pathname" "../$new_dirname/$filename"
-bash: *: command not found
dmuncy-m1:source dmuncy$ done
-bash: syntax error near unexpected token `done'
dmuncy-m1:source dmuncy$
Does anyone have an idea on why the code might have stopped working suddenly?
Thanks for any help you might be able to give me!
For the past year I've been using the following script to compile files into folders using Terminal. I deal with thousands of files so it helps out a lot. Pretty much if I have the following files:
filename1.mp4
filename1.txt
filename1.vtt
filename2.mp4
filename2.txt
filename2.vtt
It will create folders with those files compiled inside of them such as:
filename1
filename1.mp4
filename1.txt
filename1.vtt
filename2
filename2.mp4
filename2.txt
filename2.vtt
The code was working last week, but today it's giving me errors.
Here is the code:
find -iname \*asx -or -iname \*clean.txt -or -iname \*dvdIt.txt -or -iname \*.qt.\* -or -iname \*.rt\* -or -iname \*scc -or -iname \*sdf -or -iname \*smi -or -iname \*srt -or -iname \*stl | xargs rm -rf
find . -type f -print |
while read -r pathname; do
filename=${pathname##*/}
case "$filename" in
*_hi* | *_med* | *_lo*)
# strip off last underscore and following chars
new_dirname=${filename%_*}*
;;
*)
# strip off first dot and following chars
new_dirname=${filename%%.*}*
;;
esac
mkdir -p "../$new_dirname"
mv "$pathname" "../$new_dirname/$filename"
done
Here are the errors that I am getting:
dmuncy-m1:~ dmuncy$ cd /Users/dmuncy/Desktop/bin/source
dmuncy-m1:source dmuncy$ find -iname \*asx -or -iname \*clean.txt -or -iname \*dvdIt.txt -or -iname \*.qt.\* -or -iname \*.rt\* -or -iname \*scc -or -iname \*sdf -or -iname \*smi -or -iname \*srt -or -iname \*stl | xargs rm -rf
find: illegal option -- i
usage: find [-H | -L | -P] [-EXdsx] [-f path] path ... [expression]
find [-H | -L | -P] [-EXdsx] -f path [path ...] [expression]
dmuncy-m1:source dmuncy$ find . -type f -print |
> while read -r pathname; do
> * * filename=${pathname##*/}
> * * case "$filename" in
> * * * * *_hi* | *_med* | *_lo*)
-bash: syntax error near unexpected token `)'
dmuncy-m1:source dmuncy$ * * * * * * # strip off last underscore and following chars
-bash: *: command not found
dmuncy-m1:source dmuncy$ * * * * * * new_dirname=${filename%_*}*
-bash: *: command not found
dmuncy-m1:source dmuncy$ * * * * * * ;;
-bash: syntax error near unexpected token `;;'
dmuncy-m1:source dmuncy$ * * * * *)
-bash: syntax error near unexpected token `)'
dmuncy-m1:source dmuncy$ * * * * * * # strip off first dot and following chars
-bash: *: command not found
dmuncy-m1:source dmuncy$ * * * * * * new_dirname=${filename%%.*}*
-bash: *: command not found
dmuncy-m1:source dmuncy$ * * * * * * ;;
-bash: syntax error near unexpected token `;;'
dmuncy-m1:source dmuncy$ * * esac
-bash: *: command not found
dmuncy-m1:source dmuncy$ * * mkdir -p "../$new_dirname"
-bash: *: command not found
dmuncy-m1:source dmuncy$ * * mv "$pathname" "../$new_dirname/$filename"
-bash: *: command not found
dmuncy-m1:source dmuncy$ done
-bash: syntax error near unexpected token `done'
dmuncy-m1:source dmuncy$
Does anyone have an idea on why the code might have stopped working suddenly?
Thanks for any help you might be able to give me!
Last edited: