Script in Terminal No Longer Working

Joined
Nov 16, 2015
Messages
1
Reaction score
0
Points
1
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!
 
Last edited:
Joined
Feb 14, 2004
Messages
4,781
Reaction score
166
Points
63
Location
Groves, Texas
Odd... Man find lists -iname as an option, but the command throws an error. (which I believe causes the other errors)
I even checked by typing in by hand instead of copy/paste.


Ok, think I figured it out. You need to tell it WHERE to search first. Ex: find / -iname \asx.dmg Wont throw an error.
Change that and see if you still get the other errors.

Edit: for the record, using just -name threw the same error.
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top