ls | perl -nl -e '/(.*)(S[0-9]+E[0-9]+).*(\.mp4)/ && print "mv \"" . $_ . "\" \"". $1 . $2 . $3 . "\""'
How does this work? First ls
outputs the list of files, one per line, like so:
The.Big.Bang.Theory.S01E01.xxxxxxxx.mp4
The.Big.Bang.Theory.S01E02.somecrap.mp4
The.Big.Bang.Theory.S04E12.otherjunk.mp4
Then perl -nl
splits this into lines, feeding each to the regex, much like awk*. The regex captures 3 groups (denoted by parentheses), first the bit before SxxEyy, then that, then the file suffix. It then simply assembles a mv
command suitable for renaming the files, like so:
mv "The.Big.Bang.Theory.S01E01.xxxxxxxx.mp4" "The.Big.Bang.Theory.S01E01.mp4"
mv "The.Big.Bang.Theory.S01E02.somecrap.mp4" "The.Big.Bang.Theory.S01E02.mp4"
mv "The.Big.Bang.Theory.S04E12.otherjunk.mp4" "The.Big.Bang.Theory.S04E12.mp4"
This can then be inspected and once you're satisfied it does what you want, piped into a shell by appending: | sh
.
*awk would normally be a good tool to use for this, but sadly only GNU awk supports regex capture groups and Mac OS X doesn't include gawk by default.
As @laaph mentioned, if you just want to run bash commands, use a bash script.
There are, however, a few issues with your commands.
Your script has to look like:
#!/bin/sh
pushd ~/Library/Vidalia
rm vidalia.conf
unzip vidalia.conf.zip
popd
open /Applications/Vidalia.app
If you didn't change to the correct directory, unzip
would unzip the file into your home directory, or wherever you launched your script from.
There are ways to look for when an app quits, but in your case this seems useless, you're removing the .conf
whenever you launch the script anyway. But if you really want that, you could simply do:
#!/bin/sh
pushd ~/Library/Vidalia
rm vidalia.conf
unzip vidalia.conf.zip
popd
open -W /Applications/Vidalia.app
pushd ~/Library/Vidalia
rm vidalia.conf
popd
(This would make the script wait until you close the app, and then it'd delete the configuration file. Again though, this is useless and redundant if you'll be only launching the app with the script.)
Also, you could try a simpler solution: I assume that what you want is just to have the same vidalia.conf whenever you start the program. If that's the case, try just making the .conf
read-only.
Best Answer
The delay is probably due to buffering.
Try
xargs -L 1 bash myScript.sh
if you can process the data line by line.