The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 03-17-2009
jambesh's Avatar
jambesh jambesh is offline
Registered User
  
 

Join Date: Aug 2006
Location: Pune,India
Posts: 137
Extract date from log file

Hello All,

I just need to extract the date portion [ * ] from a apache log file
I am able to do it using the chain of command -

Logfile contents - First record -
==========================
197.130.211.240 - - [11/Mar/2009:01:00:00 -0700] "GET /jp/index.shtml HTTP/1.1" 200 24255 "http://www.google.co.jp/search?q=cco&lr=lang_ja&ie=utf-8&oe=
utf-8&aq=t&rls=org.mozilla:jafficial&client=firefox-a" "Mozilla/5.0 (Windows; U; Windows NT 5.1; ja; rv:1.9.0.7) Gecko/2009021910 Firefox/3.0.7" "C
TC=202.226.241.234.1211271614048643; SMIDENTITY=8dvPlQzpqd5+avTXCpx7AWCRc3IbGqY7Mm6ECeAu/lwojS/RC4qmMwC+zQCHmNJekImecfJ9e8qJQVgI8Nb7hBe4rNRzPVXPRqUxTh69a
Bp4UA5oRd5SceTwPkA+RLB/ZvSST0Bvxk1dVnmo8R50VJ+IUDqB+N2854r7x/pihcXYObu7HLRFLdAhwVNYaamwWZ8qsTwgUEfUTZLlEGTlqsJuqo+DiO1nZnUmJ1PIgfIpEHeMpzxTiSpFI7FtTWYivH
GE9WeHfJBPV6EcuWONc9pvTfB4hprbm+sW5HxlzwP6wa2RdhpdO5rrLVX8DEP/I4fKYKTu0LYm0MIrVY1/xpNsHa3EkCgQL9F6r1Ns40qry9RRfCywEGhnDTk4jCsPCGF4s7bnwypVmpraunUq/jQLaBm
zLjB/Jr/uPcNR4zpodSuGbbc/8X3INPMx/LeXxAwau79aeBC40u7yGVZXYcyhdLJrsKOqwOcMcXJbOw9aW0SmQJrzCEtnEvc0nysGttJ5PwYdDO0Mrt5CIFs/IfTSKhDUB/Oa123IVoGO15TPHjE4XoFI
Jxk6FmNojzR1I2iSLgGKF4wwR44i9sPqXWwFfTUOUuRknOu614p368dorLg6gjhOdPvyX0apnP4RZA1iGR8f8FWuyDFQfvO3Mg2f QBoTQYIYSXBu372t8HNbvspnFElLuGqtHOyuC13a; USER_PROFIL
E=eNpLTE5OLS72SS1LzbE1tgYAKM8FFg==; __utma=152635051.1371569464997210600.1234262319.1234262319.1234865834.2; __utmz=152635051.1234262319.1.1.utmcsr=(dire
ct)|utmccn=(direct)|utmcmd=(none); s_pers=%20s_nr%3D1236048421913%7C1238640421913%3B%20gpv_p20%3Dtools.cisco.com/search/jsp/search-results.get%7C12367597
50363%3B; s_sess=%20s_ria%3Dflash%252010%257C%3B%20s_cc%3Dtrue%3B%20s_sq%3D%3B" "202.227.241.239"

============================
How i am trying

dt=`head -1 log-date-checker.txt | awk -F "]" '{print $1}' | awk -F "[" '{print $2}' | cut -f1 -d" "`

echo $dt
========
Output

11/Mar/2009:01:00:00


What i need ?-

===============
Any alternate and optimal solution to pick the date portion

Any help appreciate

Thanks

Last edited by jambesh; 03-17-2009 at 01:43 PM..