Monday, February 23, 2009

how to delete blank lines using sed

Easy one liner for this:

sed '/^$/d' < inputfile

cr/lf linebreak madness

I get these log files in my work that are supposed to be text files. Supposed to be. For some bizarre reason the CRs are there (represented by ^M) while the linefeed character seems to be missing. So doing this:

sed 's/^M//g' < inputfile.txt > outputfile.txt

does NOT work.

After much searching and experimenting, this works:

perl -ne ' s/:/\n/g; print ' inputfile.txt > outputfile.txt

I have yet to find a sed version that works. Stay tuned.

PS. Check out the wikipedia entry on this for other ideas:

Sunday, February 22, 2009

Using Subversion : part 2

Next up is creating authentication settings so that only that you give permission to can access the repository.

The server accesses the svnserve.conf file in the conf subdirectory of the repository. Since I created the repository in /var/svn/myrepo, you will find the file in /var/svn/myrepo/conf/.

In the [general] section, you will need to change the values for the authentication realm, and user names/passwords as such:

password-db = mypasswdfile
realm = littletechtips

The realm is kind of the authentication namespace. The password-db is the file where the server stores the user names and passwords. This is where you put the following:

raoul = foobar
juan = foobar

Which is pretty self-explanatory. :)

Using Subversion : Part 1

I decided to use subversion for the helper (someitmes throwaway) scripts that I was using to help me with work. I was the only one who was going to use the repository as I was hosting it on a Slackware virtual machine.

It seemed easiest to use the svnserve option as the Apache httpd seemed a little too involved for what I wanted to do.

First you create your repository with something like:

$ svnadmin create /var/svn/myrepo

This creates the repository with the default filesystem data store, which is FSFS with the version of subversion I am using.

Then you start the server. Since I was using svnserve, you start it this way:

$ svnserve -d -r /var/svn/myrepo

This makes all the repositories I will place there available to anyone who wants it.

Wednesday, February 4, 2009

python tidbit on printing to string

I've been learning Python by using it in some data processing chores at work.
At some point, I wanted to be able to print to a string like you would using sprintf in C.

After some searching through the Python docs, I found StringIO which pretty much does what I wanted. There's also cStringIO, which is supposed to be a faster version of StringIO. But I'll save that for another day.

Edit: I realized that I didn't give an example how to use the StringIO module. Here's an example on how to print to string using the StringIO module.