Wednesday, October 28, 2009

How to change where sqlite3 puts it's temporary files

I recently was running out of space on the /var partition when trying to run a sqlite3 query. I tried to vacuum the database, but that also ran out of space. (Duh.) With a bit of digging, I discovered how to tell sqlite where to put the temp files:
sqlite3 ./mydb.db "PRAGMA temp_store_directory='/usr/'; vacuum"

Wednesday, October 14, 2009

awk and vi trick

Global search and replace with regular expressions is one of the things that keeps me using vi. (Tags and cscope are the other two features I really like.

Here's a variant of that task that uses awk.

The intial text was:

Men     Formal
Men     Casual
and the goal text was:
        TestDialog(1, "Men", "Formal"),
        TestDialog(2, "Men", "Casual"),
The vi command to do this is (take out new lines, blogger keeps wrapping my pre text).
:.,.+1!awk -F "\t" '{
printf "\tTestDialog(
\%d, 
\"\%s\", 
\"\%s\"
),\n", 
NR, $1, $2}'

Getting the escaping right is a bit awkward, but the benefit is you have no worries about typos, and it applies to 18 rows of data just as easly as two rows.