Saving output from ‘text to speech’ to a file on Mac OS X

In terminal you can write something like:

say 'hello world'

Which will make your computer talk. To save the audio output to a file, use the -o option. A full example is:

say -o hello.aiff -v 'Alex' 'Hello, my name is Alex'
open hello.aiff

This will say ‘Hello, my name is Alex’, in the voice of ‘Alex’ (other voice-options are ‘Bruce’, ‘Fred, ‘Kathy’, ‘Vicki’ and ‘Victoria’), and save the output to ‘hello.aiff’.

It seems there is no option for setting the speed (can be set in System preferences -> speech). See man say for all options. Interesting options include sending the output over the network.

Kill process from within top in Terminal on Mac OS X

My top seems to act a little strange (running Snow Leopard). It doesn’t respond to the key commands I’m used to, e.g. for sorting on Memory Usage etc. Nevertheless, this is how I found out (by chance really) how to kill a process from within top.

First start top using sudo:

sudo top

Press shift + s. This will promt for a signal. Enter the word ‘kill’ (if not already selected). Hit enter. Now top prompts for a pid. Enter the pid of the process you want to expedite. Hit enter. Good bye process.

Installing pip and virtualenv on Mac

These instructions show how to install pip and virtualevn on a Mac running Snow Leopard 10.6.8 and using Python 2.7. I used this to install Django 1.3.1 (installation instructions included).

Installing pip

(skip if you have pip installed)

First make sure you have either setuptools or distribute installed. Please consult your operating system’s package manager or install it manually:

curl http://python-distribute.org/distribute_setup.py | python

Continue reading “Installing pip and virtualenv on Mac”

How to put each word in a file on a separate line

Place each word on a separate line with sed and awk:

sed -e 's/[^[:alpha:]]/ /g' | awk '{ for (i=1;i<=NF;i++) print $i }'

sed is used to replace non alpha characters with spaces (optional)

awk places each word on a separate line.

Taking it a step further you can keep only unique words with the good ol’ lowercase, sort -u trick or sort|uniq if you prefer that:

awk '{ for (i=1;i<=NF;i++) print $i }' | tr "[:upper:]" "[:lower:]" | sort -u

How to split a log file into smaller files

In this example I had a big log file (many million lines), that I wanted to split into smaller logfiles (each one million lines) for processing on Elastic MapReduce.

-rw-r--r--  1 kostas staff 543067012012 Oct 11 13:45 huge_logfile

This is a job for the split command. Because individual lines in the log file must be kept intact, the -l option is used to specify the number of lines in each file. In this example, certain lines are first filtered out with grep, to show how split is used when data is piped in:

grep 'some-pattern' huge_logfile | split -a 6 -l 1000000 - log_

The dash in the split command is used to accept input from standard input, while the log_ is used as a prefix for generated filenames. The -a 6 option tells split to use a 6 character extension after the prefix when naming files. The output looks like this:

huge_logfile
log_aaaaaa
log_aaaaab
log_aaaaac
log_aaaaad
log_aaaaae
...

Check if shared library is installed on Mac OS X

One way to check whether a library is installed is to use ld, e.g. check that zlib is installed:

ld -lzlib

If library is installed you’ll get something like this:

ld: warning: -arch not specified
ld: could not find entry point "start" (perhaps missing crt1.o) for inferred architecture x86_64

If library is not installed you’ll get something like this:

ld: library not found for -lzlib