Log in

No account? Create an account
an albuquerque not animate be armada. [entries|archive|friends|userinfo]
Okrzyki, przyjaciel!

[ website | My Website ]
[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

Nerdly information [Mar. 12th, 2008|09:55 am]
Okrzyki, przyjaciel!
I have a portable hard disk that I stuck a bunch of MP3s on, which I'm using with iTunes. This gets my music files off of my work computer's hard disk, where they could be problematic with respect to the University. This led me to some conclusions:

1. ITunes could be a lot better. If there was a better OS X music library manager/player I'd use it. ITunes does not play well with fiddling around with your music files the way I've been doing. At one point I had to write a shell script to erase all the duplicate files ITunes created when I deleted all the tracks from the database and told it to import all my music files.

2. Shell scripts have trouble dealing with special characters. Something I commonly do in the C Shell:

foreach x ( `find ...` )
do something to $x

which basically goes through every file in a directory tree and do something to everything found. If there are any spaces, parenthesis or exclamation points in the filenames (like the regrettably named band !!!), this method doesn't work. I ended up dumping out the names of all the mp3 files I wanted deleted into a file, and then using emacs macros to make 3000 shell commands to execute to delete the duplicate files. Even then I had to make several passes to escape special characters.

3. At least on a Mac, Firewire rules all over USB 2.0. I have a portable drive with both interfaces, and using the Firewire is noticeably faster. Haven't played with it on PC, but at some point I want to build a fault tolerant RAID array for storage at home, and hook it up to FW800. Anyone know of a reasonably priced RAID tower?

[User Picture]From: mkb_technologie
2008-03-12 03:43 pm (UTC)
foreach x ( `find ...` )
do something to $x

in bash at least, you can surround $x with double quotes to avoid interpretation of special characters while retaining variable expansion.

iTunes can PROBABLY be fixed if you don'task it to make copies and do file organization on your own.
(Reply) (Thread)
[User Picture]From: mkb_technologie
2008-03-12 03:44 pm (UTC)
also, find -print0 | xargs -0 makes things a lot easier than foreach

Edited at 2008-03-12 03:45 pm (UTC)
(Reply) (Parent) (Thread)
[User Picture]From: chaircrusher
2008-03-12 03:57 pm (UTC)
The problem is the backquote expansion. And the reason for looping is that i can do some conditional stuff and fancy-pants sed editing in a loop where it's kind of difficult to do in-line with xargs.

And I do use the find/xargs pattern a lot as well.

I think the one tool that would be the most useful for simple ad hoc things like this would be Awk, but I don't think to use it often enough to remember the syntax. Or Perl, or even Tcl. That's the Unix way -- let a hundred flowers bloom.

And here's what I wanted to do with foreach in C-shell, but for backquotes not working:

foreach x (`find . -name '*mp3'`)
set y=`echo $x | sed -e 's/ [0-9]\.mp3/.mp3'`
if ( -f $y ) then
rm -f $x

On OS X AppleScript would be a great tool, but I can't be arsed to learn yet another language.
(Reply) (Parent) (Thread)