Grepping only dates from a log file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grepping only dates from a log file
# 1  
Old 05-28-2014
Grepping only dates from a log file

Hi All,

I have a log file where every line contains a date and some other data, i want to grep only the date from every line to a different file.

Please help how to get this.

Thanks in advance !!
# 2  
Old 05-28-2014
What format is the date in? If it's dd-mm-yyyy, a crude way is to do this:
Code:
grep -o "[0-9]\{2\}-[0-9]\{2\}-[0-9]\{4\}"

This User Gave Thanks to balajesuri For This Post:
# 3  
Old 05-28-2014
Hey Bala,

Thanks for helping,

date format in my log is " mm/dd/yyyy "

using your grep command, i think the same command will work

Code:
grep -o "[0-9]\{2\}-[0-9]\{2\}-[0-9]\{4\}"

pl suggest.

many Thanks !!

Last edited by radoulov; 05-28-2014 at 07:30 AM..
# 4  
Old 05-28-2014
Quote:
Originally Posted by nanz143
Hey Bala,

Thanks for helping,

date format in my log is " mm/dd/yyyy "

using your grep command, i think the same command will work

grep -o "[0-9]\{2\}-[0-9]\{2\}-[0-9]\{4\}"

pl suggest.

many Thanks !!
Here your answer

Code:
grep -o "[0-9]\{2\}/[0-9]\{2\}/[0-9]\{4\}"

This User Gave Thanks to vinhnch For This Post:
# 5  
Old 05-28-2014
thank you so much... will test and get back to you ..

---------- Post updated at 06:14 AM ---------- Previous update was at 06:01 AM ----------

Hey bala there is an error,

Code:
grep: illegal option -- o
Usage: grep -hblcnsviw pattern file . . .

My OS is Solaris 10

---------- Post updated at 06:27 AM ---------- Previous update was at 06:14 AM ----------

correction to my question i need to print only dates in the line
# 6  
Old 05-28-2014
Show sample of your log file
# 7  
Old 05-28-2014
Code:
Server1111 I will be changing the characterset used by the O08FTM2 database. mail by alan stanke (Expire: 01/21/2014)

Server2222 From: Windows_L1 (Expire: 01/17/2014)

server3201 From: Windows_L1 (Expire: 01/17/2014)

server3206 From: Windows_L1 (Expire: 01/17/2014)

server3205 From: Windows_L1 (Expire: 01/17/2014)

server3204 From: Windows_L1 (Expire: 01/17/2014)

server1022 Got Cannot Pings after removing from MM after cleanup activity (Expire: 01/19/2014)

server1013 Got Cannot Pings after removing from MM after cleanup activity (Expire: 01/19/2014)

these are few rows of my log, i need to print only the date

Last edited by Scott; 05-29-2014 at 09:02 AM.. Reason: Code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to read a log file and run 2nd script if the dates match

# cat /tmp/checkdate.log SQL*Plus: Release 11.2.0.1.0 Production on Mon Sep 17 22:49:00 2012 Copyright (c) 1982, 2009, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production FIRST_TIME NEXT_TIME... (1 Reply)
Discussion started by: SarwalR
1 Replies

2. UNIX for Dummies Questions & Answers

How to write the dates between 2 dates into a file

Hi All, I am trying to print the dates that falls between 2 date variables into a file. Here is the example. $BUS_DATE =20120616 $SUB_DATE=20120613 Output to file abc.txt should be : 20120613,20120614,120120615,20120616 Can you pls help me accomplish this in LINUX. Thanks... (5 Replies)
Discussion started by: dsfreddie
5 Replies

3. UNIX for Dummies Questions & Answers

grepping log files

I have a log file and I have two unique strings which represent the start and end of the text I want to obtain. How can I get all the text inbetween this start string and the end string? Thanks (2 Replies)
Discussion started by: chrisjones
2 Replies

4. Shell Programming and Scripting

How to processing the log file within certain dates based on the file name

Hi I am working on the script parsing specific message "TEST" from multiple file. The log file name looks like: N3.2009-11-26-03-05-02.console.log.tar.gz N4.2009-11-29-00-25-03.console.log.tar.gz N6.2009-12-01-10-05-02.console.log.tar.gz I am using the following command: zgrep -a --text... (1 Reply)
Discussion started by: shyork2001
1 Replies

5. Shell Programming and Scripting

Grepping log file

Dear All, I have a log file that is dislpayed as: <msg time='2009-10-14T05:46:42.580+00:00' org_id='oracle' comp_id='tnslsnr' type='UNKNOWN' level='16' host_id='mtdb_a' host_addr='UNKNOWN' version='1'> <txt>14-OCT-2009 05:46:42 *... (19 Replies)
Discussion started by: x-plicit78
19 Replies

6. Shell Programming and Scripting

find log file between two dates

Dear All, Please can you help me to crack this query? If the log files for the task above all had a naming convention of myoutput_YearMonthDay.log (i.e. myoutput_20060215) How would you find only those log files created between the 10th and the 20th of each month going back the last 365 days.... (1 Reply)
Discussion started by: justin_mca
1 Replies

7. Shell Programming and Scripting

Grepping the last 30 minutes of a log file...

I need to know if anyone can assist me on how to grab the last (we'll just say "x" minutes) of a log file. How do you tell the grep command without specifying an exact window of time? (So relative instead of absolute.) Thanks, Jon (2 Replies)
Discussion started by: jtelep
2 Replies

8. Shell Programming and Scripting

grep a log file to filter previous dates

Hi, I have problem of filtering a log file from my perl script. #cat /data/pinpe.csv_20070731 | nawk -v FS=, '{print $1','$18','$22','$26}' | grep -w 100 | grep -w 1 | nawk '{print $4}' Below is the output: 2009-06-16 2009-01-29 2009-06-02 2008-03-05 2007-08-05 2007-09-24... (5 Replies)
Discussion started by: pinpe
5 Replies

9. Shell Programming and Scripting

grep a log file between 2 dates

Hi Currently I can grep a log file with the following command: $results = `grep -A 2 '^$date.$time.*' $log`; and the following arguments: $date = 2007/04/25 $time = 16:07 Log example: 2007/04/25 16:07:12.145701 2007/05/25 14:07:12.145701 2007/05/25 17:07:12.145701 2007/06/25... (37 Replies)
Discussion started by: Epiphone
37 Replies

10. Shell Programming and Scripting

help searching log file with dates

Im tyring to create a script that will show me any lines in a file with todays date and yesterdays, the date format in the file is as follows ----- amqxfdcx.c : 728 -------------------------------------------------------- 07/12/05 09:53:20 AMQ6109: An internal WebSphere MQ error has... (3 Replies)
Discussion started by: csaunders
3 Replies
Login or Register to Ask a Question