Monday, March 26, 2007

Extracting fields from a file

Have you every wanted to extract a particular field from a flat file that was hundreds or thousands of lines long?

Now, I bet your saying, sure you could import the file into Excel, OpenOffice.org Spreadsheet or some other spreadsheet application, but what fun would that be. That would mean using your mouse, but your a keyboard kind-of-person. In addition, opening very large files may leave spreadsheet applications very sluggish.

So whats the alternative? AWK (or gawk). Awk is a command line program that can do just what you wish. For example, lets say that you wanted to extract all the full names from your system's /etc/passwd file. Now you could import the file in your favorite spreadsheet application, specify a delimiter, and wait for it to process, depending on the size of your passwd file. Alternatively, you could run the following awk command:

awk -F: '{print $5}' /etc/passswd

This command uses the '-F' flag to specify the semicolon as a delimiter. The 'print $5' section tells the program to print out the 5th field in the file. Finally /etc/passwd specifies the file to extract the field from.

Now I bet you are saying, so what? How did this help me at all, and why didn't I just use the spreadsheet? Well, not only did you not have to import the file into the spreadsheet program, but you can easily pipe the output of this program to other useful applications that allow you to accomplish what you need to. A quick example, is the ability to pipe the output through the 'sort' command which will then list the users full names in alphabetical order.

Still not convinced that this was easier than opening your precious spreadsheet application. When you are referencing a data source that changes often, such as the passwd file on high usage *nix systems, awk definitely pulls its weight. You could easily setup an alias, or a shell script to execute the command for you, and now you can simply type a few characters and hit enter as opposed to fiddling with your spreadsheet, waiting for it to import the data, and dealing with the slow responsiveness as all your system memory is used up.

Give it a try.

Sunday, March 25, 2007

Beryl: Lack of Dual Video Card Support

I recently upgraded from one EVGA Gefore 6800 PCI Express card which had two 19" Widescreen Samsung Syncmaster monitors to two Gigabyte Geforce 7300 LE video cards. Since they were both nvidia cards, the upgrade was quite easy. I was required to make a few updates in the /etc/X11/xorg.conf. These weren't to bad. It required adding another video card section, or 'device' and then linking that device to one of the other monitors and adding it to the server layout.

The really disappointing thing was the lack of beryl support for multiple video cards. At first I thought that some configuration item was messed up, so I started troubleshooting. I closed beryl manager and opened beryl through the command prompt and I was able to see the error regarding ROR which would not allow beryl to start.

I started looking through the forums on the beryl website and I did find a few places that explained why this was not possible, although there were a few posts that eluded to the possibility of two video cards and beryl. In order to clear up confusion, I created a post to try to get a straight answer. After a few days, I received no response, so I posted again.....still no response. Here is the link to the forum post. Maybe someone will reply, but until then it seems impossible to use beryl with two video cards and one extended desktop. (Note: Beryl does work with two video cards if you use two separate X sessions. You can still drag the mouse between them screen, but you cannot drag windows between the sessions or interact in any other way.)

Auto Complete

Possibly the single greatest feature in a Linux system is auto complete. If you have never used this feature before, open a shell and start typing a command, and press the 'Tab' key before you finish typing it.

This feature saves so much time when typing commands and especially paths. But it isn't just a time saver.

Another great use for it is to verify the existence of files and directories. For instance, if you think a file exists in /etc/apt/ called sources.list but you aren't sure, you can type:

'less' (or cat or more) followed by '/etc/apt' and then start pressing the 'Tab' key. The auto complete feature will first add a '/' to the end of '/etc/apt', which verifies that it is in fact a directory, and then when you continually press tab, it will display the files within the directory.

Mastering the use of the auto complete feature is one of the first steps to saving yourself a lot of time when using the command line.

Thursday, March 01, 2007

Apache2 and SSL on Ubuntu

A perfect small guide to setup apache2 and ssl on ubuntu:
(from: http://ubuntuforums.org/archive/index.php/t-4466.html)

A Mini-Howto for apache2: :)

apt-get install apache2
apache2-ssl-certificate
(and answer the questions)

Now, enable ssl:
a2enmod ssl

configure ssl:
cp /etc/apache2/sites-available/default /etc/apache2/sites-available/ssl
ln -s /etc/apache2/sites-available/ssl /etc/apache2/sites-enabled/ssl
"/etc/apache2/sites-enabled/ssl" should look like this:

NameVirtualHost *:443

(... configure the directories too...)
and "/etc/apache2/sites-enabled/default" should look like this:

NameVirtualHost *:80

(... configure the directories too...)
In /etc/apache2/ports.conf, add Listen 443

In the middle of /etc/apache2/sites-available/ssl file, insert this two lines:

SSLEngine On
SSLCertificateFile /etc/apache2/ssl/apache.pem

Hope it helps :)