Consider this: $ grep Girish access.log
67.18.176.31 - - [16/Oct/2009:15:03:37 -0700] "GET /images/spam-cheetah.jpg HTTP/1.1" 200 12580 "http://aplawrence.com/Girish/gv-rrdtool.html" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3" 64.60.156.46 - - [16/Oct/2009:15:08:16 -0700] "GET /images/spam-cheetah.jpg HTTP/1.1" 200 12580 "http://aplawrence.com/Girish/ntp.html" "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; InfoPath.2; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 2.0.50727)" 99.20.134.12 - - [16/Oct/2009:15:12:52 -0700] "GET /images/spam-cheetah.jpg HTTP/1.1" 200 12580 "http://aplawrence.com/Girish/spiderweb.html" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/532.0 (KHTML, like Gecko) Chrome/3.0.195.27 Safari/532.0" 75.46.209.253 - - [16/Oct/2009:15:36:09 -0700] "GET /images/spam-cheetah.jpg HTTP/1.1" 200 12580 "http://aplawrence.com/Girish/gv-rrdtool.html" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)" 76.120.68.138 - - [16/Oct/2009:15:53:23 -0700] "GET /images/spam-cheetah.jpg HTTP/1.1" 200 12580 "http://aplawrence.com/Girish/gv-rrdtool.html" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_1; en-us) AppleWebKit/531.9 (KHTML, like Gecko) Version/4.0.3 Safari/531.9" 216.10.193.22 - - [16/Oct/2009:16:55:13 -0700] "GET /images/spam-cheetah.jpg HTTP/1.1" 304 174 "http://aplawrence.com/Girish/perl-cpan.html" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; MS-RTC LM 8; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)" I am interested in the referer field that fetches the logo image from my website. I want to know which of my articles are drawing the most readers. I can use to cut to find out. First the solution. Then the explanation. $ grep Girish access.log | cut -d\" -f4 http://aplawrence.com/Girish/gv-rrdtool.html http://aplawrence.com/Girish/gv-rrdtool.html http://aplawrence.com/Girish/gentle-routing.html http://aplawrence.com/Girish/gv-rrdtool.html http://aplawrence.com/Girish/ntp.html http://aplawrence.com/Girish/spiderweb.html http://aplawrence.com/Girish/gv-rrdtool.html What did I do? I split the line into multiple fields using double quote(") as the field separator. I had to use a backslash since the shell gets confused when you use a single or a double quote without closing. Think of cut(1) as a son/daughter of grep. grep fetches relevant lines from a text file. cut fetches relevant fields from a line. cut is a very powerful command. Please learn it thoroughly. It is very useful in shell scripts. I will give you one more real life example. I want to find out the disk size of a medium on which the user wishes to install SpamCheetah. It could be a hard disk(IDE/SCSI/SATA) or it could be a USB memory stick or a USB hard disk or a DOM flash. Before I proceed I want to ensure that the disk space is sufficient and I also want the user to identify the drive in question from the size reported. I use the BSD disklabel(8) command for that. But I want only the size and not other stuff on the line. There is one more detail. No shell utility will be able to multiply the disklabel result with 512 without overflowing. Nowadays you have massive disks... So I resorted to using a high precision calculator bc(1) in batch mode. There are many other uses for cut. -Girish -- Gayatri Hitech web: http://gayatri-hitech.com SpamCheetah Spam filter: http://spam-cheetah.com _______________________________________________ To unsubscribe, email ilugc-requ...@ae.iitm.ac.in with "unsubscribe <password> <address>" in the subject or body of the message. http://www.ae.iitm.ac.in/mailman/listinfo/ilugc