Sponsored Content
Full Discussion: Extract date from log file
Top Forums Shell Programming and Scripting Extract date from log file Post 302298430 by jambesh on Tuesday 17th of March 2009 01:06:18 PM
Old 03-17-2009
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:jaSmiliefficial&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 02:43 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract Date from file

I am new to unix scripting. we are using bash. My task is I have dir which contains 30 files. The first column in each file is Date field. For all the files I need to extract the date part Ex(2007-09-05) from the file and add that at the end of that file. for example: The file names are... (2 Replies)
Discussion started by: magi
2 Replies

2. Shell Programming and Scripting

How to extract date with time from file

Hi, I have a file where there is a date and time field, the format for it is yyyy-mm-dd hours:mins:sec the position of date field may vary anywhere in the line and it might be different and it is specified along with the variable AppTimeStamp how do i extract date and time both from the... (5 Replies)
Discussion started by: prash_b
5 Replies

3. Shell Programming and Scripting

Extract data from log file from or after the specific date

Hi , I am having a script which will start a process and appends the process related logs to a log file. The log file writes logs with every line starting with date in the format of: date +"%Y %b %d %H:%M:%S". So, in the script, before I start the process, I am storing the date as DATE=`date +"%Y... (5 Replies)
Discussion started by: chiru_h
5 Replies

4. Shell Programming and Scripting

Extract info from log file and compute using time date stamp

Looking for a shell script or a simple perl script . I am new to scripting and not very good at it . I have 2 directories . One of them holds a text file with list of files in it and the second one is a daily log which shows the file completion time. I need to co-relate both and make a report. ... (0 Replies)
Discussion started by: breez_drew
0 Replies

5. Shell Programming and Scripting

How to extract log data based on date

Hi Gurus, I've been having some problem in extracting the log data based on the current date and month. As shown in the sample data below, how to extract the log info for Aug 11? Sample data: root pts/ta userpc Wed Aug 11 09:46 - 20:21 (10:35) root pts/ta userpc... (13 Replies)
Discussion started by: superHonda123
13 Replies

6. Shell Programming and Scripting

How to extract log data based on current date and month ?

Hi Gurus, I'm using HP-UX B.11.23 operating system. I've been trying to extract this log info based on the current date and month, but was having some issues as the date column which on the 4th column has a comma and the 5th column has a dot tied to it. Here is the output from my shut... (5 Replies)
Discussion started by: superHonda123
5 Replies

7. Shell Programming and Scripting

Delete log files content older than 30 days and append the lastest date log file date

To delete log files content older than 30 days and append the lastest date log file date in the respective logs I want to write a shell script that deletes all log files content older than 30 days and append the lastest log file date in the respective logs This is my script cd... (2 Replies)
Discussion started by: sreekumarhari
2 Replies

8. UNIX for Dummies Questions & Answers

Extract date ranged data from log file

Hi, I am trying to extract lines of data within a log file on a Redhat 5 Linux system. eg I need all the lines with a particular username over the last 3 minutes. the log file may read like this, and I want a way to search all the lines extracting all the relevant lines over the last 3... (2 Replies)
Discussion started by: mantis100
2 Replies

9. UNIX for Dummies Questions & Answers

How to extract date from a file?

Hello Gurus, I have one file from which I want to extract only dates. The below is the file format : ========================= Process ID 16842770 Log Read Checkpoint Oracle Integrated Redo Logs 2014-07-04 17:06:11 <=== SCN 1779.852353022 (7641599172606) Process ID ... (6 Replies)
Discussion started by: pokhraj_d
6 Replies

10. UNIX for Dummies Questions & Answers

AIX UNIX - script on how to extract from log file with previous date

Hello, I am new to this forum so any assistance would help. I am currently trying to develop a script that extract all data from a log file with has the previous day's date. $ <root@aixtest3> /var/log > more sudo.log May 13 10:52:10 aixtest3 local2:notice sudo: tbrath : TTY=unknown ; ... (14 Replies)
Discussion started by: Kslew82
14 Replies
jfs_fscklog(8)						   Extract/Display JFS fsck Log 					    jfs_fscklog(8)

NAME
jfs_fscklog - extract a JFS fsck service log into a file and/or format and display the extracted file SYNOPSIS
jfs_fscklog [ -d ] [ -e device ] [ -f output.file ] [ -p ] [ -V ] DESCRIPTION
jfs_fscklog with option -e device extracts the contents of either the most recent or immediately prior (specified with option -p) JFS fsck service log from the specified device, and writes the output to a file. The file name may be specified with the -f option, or the default file name is <pwd>fscklog.new. If the -p option is used, the default file name is <pwd>fscklog.old. jfs_fscklog with option -d formats and displays the contents of the extracted file. jfs_fscklog with options -d and -e device extracts and displays the JFS fsck service log. OPTIONS
-d Format and display a previously extracted JFS fsck service log. -e device Extract the JFS fsck service log from device and store it in a file. (device is the special file name corresponding to the actual device from which the fsck log will be extracted (e.g. /dev/hdb1 )). -f file.name Specify the file name, overriding the default file name. When used with -e device, file.name specifies the name of the file into which the JFS fsck log will be extracted. When used with -d, file.name specifies the name of the extracted file whose contents will be formatted and displayed. file.name must be 127 characters or less in length. file.name will be created in the present working directory unless it is fully qualified. -p Extract the prior log (as opposed to the most recent log). -V Print version information and exit (regardless of any other chosen options). EXAMPLES
Extract the most recent JFS fsck log on /dev/hda5 into <pwd>fscklog.new: jfs_fscklog -e /dev/hda5 Extract the most recent JFS fsck log on /dev/hdb3 into /temp/l9651107.log: jfs_fscklog -e /dev/hdb3 -f /temp/l9651107.log Display the JFS fsck log that was extracted into /temp/l9651107.log: jfs_fscklog -d -f /temp/l9651107.log Extract and display the previous JFS fsck log from /dev/hda8: jfs_fscklog -e /dev/hda8 -d -p REPORTING BUGS
If you find a bug in JFS or jfs_fscklog, please report it via the bug tracking system ("Report Bugs" section) of the JFS project web site: http://jfs.sourceforge.net/ Please send as much pertinent information as possible, including any jfs_fscklog error messages and the complete output of running jfs_fsck with the -v option on the JFS device. SEE ALSO
jfs_fsck(8), jfs_mkfs(8), jfs_tune(8), jfs_logdump(8), jfs_debugfs(8) AUTHOR
Barry Arndt (barndt@us.ibm.com) jfs_fscklog is maintained by IBM. See the JFS project web site for more details: http://jfs.sourceforge.net/ October 28, 2002 jfs_fscklog(8)
All times are GMT -4. The time now is 11:22 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy