Forums
New posts
Articles
Product Reviews
Policies
FAQ
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Menu
Log in
Register
Install the app
Install
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
Script in Terminal No Longer Working
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="dmuncy" data-source="post: 1686666" data-attributes="member: 364510"><p>Hello All, </p><p></p><p>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:</p><p></p><p>filename1.mp4</p><p>filename1.txt</p><p>filename1.vtt</p><p>filename2.mp4</p><p>filename2.txt</p><p>filename2.vtt</p><p></p><p>It will create folders with those files compiled inside of them such as:</p><p><strong>filename1</strong></p><p> filename1.mp4</p><p> filename1.txt</p><p> filename1.vtt</p><p><strong>filename2</strong></p><p> filename2.mp4</p><p> filename2.txt</p><p> filename2.vtt</p><p></p><p>The code was working last week, but today it's giving me errors. </p><p></p><p>Here is the code:</p><p></p><p>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</p><p>find . -type f -print |</p><p>while read -r pathname; do</p><p> filename=${pathname##*/}</p><p> case "$filename" in</p><p> *_hi* | *_med* | *_lo*)</p><p> # strip off last underscore and following chars</p><p> new_dirname=${filename%_*}*</p><p> ;;</p><p> *)</p><p> # strip off first dot and following chars</p><p> new_dirname=${filename%%.*}*</p><p> ;;</p><p> esac</p><p> mkdir -p "../$new_dirname"</p><p> mv "$pathname" "../$new_dirname/$filename"</p><p>done</p><p></p><p></p><p></p><p>Here are the errors that I am getting:</p><p></p><p>dmuncy-m1:~ dmuncy$ cd /Users/dmuncy/Desktop/bin/source</p><p>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</p><p>find: illegal option -- i</p><p>usage: find [-H | -L | -P] [-EXdsx] [-f path] path ... [expression]</p><p> find [-H | -L | -P] [-EXdsx] -f path [path ...] [expression]</p><p>dmuncy-m1:source dmuncy$ find . -type f -print |</p><p>> while read -r pathname; do</p><p>> * * filename=${pathname##*/}</p><p>> * * case "$filename" in</p><p>> * * * * *_hi* | *_med* | *_lo*)</p><p>-bash: syntax error near unexpected token `)'</p><p>dmuncy-m1:source dmuncy$ * * * * * * # strip off last underscore and following chars</p><p>-bash: *: command not found</p><p>dmuncy-m1:source dmuncy$ * * * * * * new_dirname=${filename%_*}*</p><p>-bash: *: command not found</p><p>dmuncy-m1:source dmuncy$ * * * * * * ;;</p><p>-bash: syntax error near unexpected token `;;'</p><p>dmuncy-m1:source dmuncy$ * * * * *)</p><p>-bash: syntax error near unexpected token `)'</p><p>dmuncy-m1:source dmuncy$ * * * * * * # strip off first dot and following chars</p><p>-bash: *: command not found</p><p>dmuncy-m1:source dmuncy$ * * * * * * new_dirname=${filename%%.*}*</p><p>-bash: *: command not found</p><p>dmuncy-m1:source dmuncy$ * * * * * * ;;</p><p>-bash: syntax error near unexpected token `;;'</p><p>dmuncy-m1:source dmuncy$ * * esac</p><p>-bash: *: command not found</p><p>dmuncy-m1:source dmuncy$ * * mkdir -p "../$new_dirname"</p><p>-bash: *: command not found</p><p>dmuncy-m1:source dmuncy$ * * mv "$pathname" "../$new_dirname/$filename"</p><p>-bash: *: command not found</p><p>dmuncy-m1:source dmuncy$ done</p><p>-bash: syntax error near unexpected token `done'</p><p>dmuncy-m1:source dmuncy$ </p><p></p><p></p><p>Does anyone have an idea on why the code might have stopped working suddenly?</p><p></p><p>Thanks for any help you might be able to give me!</p></blockquote><p></p>
[QUOTE="dmuncy, post: 1686666, member: 364510"] 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: [B]filename1[/B] filename1.mp4 filename1.txt filename1.vtt [B]filename2[/B] 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! [/QUOTE]
Verification
Name this item 🌈
Post reply
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
Script in Terminal No Longer Working
Top