Extracting data from a log file with date formats


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extracting data from a log file with date formats
# 1  
Old 02-17-2011
Extracting data from a log file with date formats

Hello,

I have a log file for the year, which contains lines starting with the data in the format of YYYY-MM-DD. I need to get all the lines that contain the DD being 04, how would I do this? I tried using grep "*-*04" but it didn't work.

Any quick one liners I should know about?

Thank you.
# 2  
Old 02-17-2011
Try:
Code:
awk -F- '$3~"04"' file

# 3  
Old 02-17-2011
Quote:
Originally Posted by cpickering
Hello,

I have a log file for the year, which contains lines starting with the data in the format of YYYY-MM-DD. I need to get all the lines that contain the DD being 04, how would I do this? I tried using grep "*-*04" but it didn't work.
grep takes regular expressions, not globs, and in regular expressions, * means "zero or more of the previous character". So the first * did nothing, and the second * means "match any number of - characters". If you want to match zero or more of any character you can use the special "." character, like:

Code:
grep ".*-.*-04"

though I'd specify it a bit further so those *'s don't get out of control and try to match the entire line, like
Code:
grep "[0-9][0-9][0-9][0-9]-[0-9][0-9]-04"

This User Gave Thanks to Corona688 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Parse apache log file with three different time formats

Hi, I want to parse below file and Write a function to extract the logs between two given timestamp. Apache (Unix) Log Samples - MonitorWare The challenge here is there are three date and time format. First :- 07/Mar/2004:16:05:49 Second :- Sun Mar 7 16:02:00 2004 Third :- 29-Mar... (6 Replies)
Discussion started by: sahil_shine
6 Replies

2. Shell Programming and Scripting

Extracting data from rsync log

Hi I have a daily rsync that runs and i am trying to find a easy way of extracting the start time and end time of the sync and extract the details of how much data was copied. I would like to use this information to see if i can increase the amount of rsyncs that run in a day. so the log... (3 Replies)
Discussion started by: treds
3 Replies

3. Shell Programming and Scripting

Error while extracting data from log file

I am running awk command to extract data from log file to calculate last 15 minutes log using below command and now i am getting bellow error: awk '$0>=$from' from=$(`date -u +"####<%d-%b-%Y %H:%M:%S o'clock GMT>"-15min`) test.log Error: date: 0551-402 Invalid character in date/time... (8 Replies)
Discussion started by: oberoi1403
8 Replies

4. 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

5. Shell Programming and Scripting

Extracting the last 10mins worth of data in a log file

Hi all, Hope someone here will be able to help me. Our system has some scripts that are run from a cron job every ten mins and is used to see how many error there are in that time frame. Problem is that in the scripts grep is used to find the data, but as the day goes on these log file grow to a... (7 Replies)
Discussion started by: Goldengreen
7 Replies

6. Shell Programming and Scripting

Extracting log entries from a date onwards

One of the log file looks like entries as below. Wed Apr 6 14:51:18 2011 FAIL LOGIN: Client "9.191.21.54" Wed Apr 6 14:52:53 2011 CONNECT: Client "9.191.21.54" Wed Apr 6 14:52:54 2011 OK LOGIN: Client "9.191.21.54" Wed Apr 6 14:55:10 2011 CONNECT: Client "9.191.21.54" Wed Apr 6... (2 Replies)
Discussion started by: rijeshpp
2 Replies

7. Homework & Coursework Questions

extracting date from log file

You are given a 1 year logfile with each line starting with a date in the form “YYYY-MM-DD”. How would you extract logs from the 4th day of each month and put them into a new file (1 Reply)
Discussion started by: DOkuwa
1 Replies

8. Shell Programming and Scripting

Extracting data from two date entries

Hi again: I have this file: "2010-11-1 11:50:00",40894,13.38,17.24,12.92,13.23,"2010-11-14 11:43:02",12.56,"2010-11-14 11:46:02",22.68,20.95,"2010-11-14 11:44:03",2.144,2.078,190.4,14.27,6.293,"2010-11-14 ... (2 Replies)
Discussion started by: iga3725
2 Replies

9. 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

10. Shell Programming and Scripting

Perl: Extracting date from file name and comparing with current date

I need to extract the date part from the file name (20080221 in this ex) and compare it with the current date and delete it, if it is a past date. $file = exp_ABCD4_T-2584780_upto_20080221.dmp.Z really appreciate any help. thanks mkneni (4 Replies)
Discussion started by: MKNENI
4 Replies
Login or Register to Ask a Question