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



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Extract Expiry date and server_name from the following file pareshan Shell Programming and Scripting 0 03-16-2009 05:03 PM
How to extract date with time from file prash_b Shell Programming and Scripting 5 06-18-2008 08:30 AM
Extract Date from file magi Shell Programming and Scripting 2 09-30-2007 12:07 AM
extract date skumar11 Shell Programming and Scripting 3 09-12-2007 10:59 PM
extract date portion from file misenkiser Shell Programming and Scripting 5 10-06-2006 05:37 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-17-2009
jambesh's Avatar
jambesh jambesh is offline
Registered User
  
 

Join Date: Aug 2006
Location: Pune,India
Posts: 136
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..
  #2 (permalink)  
Old 03-17-2009
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,116
Code:
echo '198.133.219.248 - - [11/Mar/2009:01:00:00 -0700] "GET /jp/index.shtml HTTP/1.1" 200 24255' | sed 's#[^[]*[[]\([^]][^]]*\).*#\1#'
  #3 (permalink)  
Old 03-17-2009
jambesh's Avatar
jambesh jambesh is offline
Registered User
  
 

Join Date: Aug 2006
Location: Pune,India
Posts: 136
Thanks Vgersh
It works !

Last edited by jambesh; 03-17-2009 at 01:49 PM..
  #4 (permalink)  
Old 03-17-2009
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,116
'[^[]*[' - any character BUT '[' repeated 0 or more times followed by '['.
'[^]][^]]*' - any character BUT ']' repeated 1 or more times
  #5 (permalink)  
Old 03-17-2009
jambesh's Avatar
jambesh jambesh is offline
Registered User
  
 

Join Date: Aug 2006
Location: Pune,India
Posts: 136
thank you for your help
I appreciate your valuable time.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 02:24 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0