How to implement this script on a Mac
You could save the script as ~/Scripts/weasels.sh with any text editor, and run it with bash ~/Scripts/weasels.sh ~/Documents/input\ file.txt. Or if you use TextMate, you can run the script with just ⌘R.

If you want to run the script with weasels instead of bash ~/Scripts/weasels.sh, you can make it executable and add its folder to the path:

mv ~/Scripts/weasels.sh ~/Scripts/weasels
chmod +x ~/Scripts/weasels
echo 'export PATH=~/Scripts:$PATH' &gt;&gt; ~/.bash_profile
. ~/.bash_profile
weasels ~/Documents/input\ file.txt