Grep How To - Part 1

February 7th, 2007

Here are a few little tid bits that I use on a daily basis with the awesome Grep command line tool.

Grep allows you to search files for symbols or strings (groups of characters like words) and will return the files that the search sting is found in. For example you want to search a website’s access log file for a recent traffic that came from a search engine. Most search engine referral urls have a question mark in them. The Grep command would look something like this:

grep [search string] [file name]

grep “?” /www/logs/golod.com-access.log

I use the double quotes around the question mark so that grep doesn’t get confused by a symbol, the third part is the location of the file on my server that I want to search.

Now let’s say you get a slew of information and you really only want to see searches that came in on a specific date. Since apache is configured to format my log files with a date like 07/Feb as the date I would “pipe” the results or pass them to another grep command. This looks like:

grep [search string] [file name] | grep [2nd search string]

grep “?” /www/logs/golod.com-access.log | grep “07/Feb”

This essentially passes the results of the first grep search to the 2nd grep search for further refinement.

One last thing that I use all of the time with Grep is the -v operator. Adding -v to your grep statement allows you to eliminate results that match a certain search string. Using our example:

grep [search string] [file name] | grep [2nd search string] | grep -v [search string]

grep “?” /www/logs/golod.com-access.log | grep “07/Feb” | grep -v “yahoo”

This would give us the same results as before, but it would remove any of the results that had the string yahoo anywhere in them.

Hopefully, this helps.

tags: , , ,

My Linux How To

January 12th, 2007

Welcome aboard. This new sub-site is going to chronicle my foray into using Linux as my desktop Operating System of choice.  I am not sure that I will be happy all of the time, as I like all of my windows applications, but I am going to give it a shot for a number of reasons.

First, it is not as much of a resource hog as Windows is and I am going to be building a couple of Linux machines on some super-cheap ASUS Terminator barebones systems.  They will cost me $79 +shipping each and I will have to throw some “old” SDRAM and a hard drive into them. Other than that, they are ready to go, with an 800MHz Via processor and all. I will be putting Ubuntu Linux on these and using the RDesktop application to Remote Desktop into a windows 2003 Small Business Server.  Hopefully, this will work as well as I expect.

Secondly, it is free. Not that I cannot afford to buy Microsoft OSes, I just like the idea of a “free” open source system that has thousands of people contributing to it every day.  Linux has been around for many, many years and is running the vast majority of web servers out there today. So, it is clearly up to the task of running some dumpy desktop boxes for me.

Lastly, I am a rookie PHP programmer and I want to do more scripting with PERL and Python in the coming years, so why not make it easier to do so, by running the same system that all of my web server boxes run?

I will be posting updates, tips and how-to’s for Linux installation, administration and day-to-day use. Hopefully, I will learn enough that I will have something to post here.

tags: , , ,