Grep content between timestamp


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grep content between timestamp
# 8  
Old 09-30-2010
Pls somebody help on this issue..


Thanks in Advance.

Regards,
Steve
# 9  
Old 10-01-2010
-----
# 10  
Old 10-01-2010
Hi rdcwayx,

You gave me the below script.. its greping only the mentioned time. but i want to do the same for all the hours in default.

Pls help


awk '/29\/09\/2010 01:00/,/userAttr/' infile
# 11  
Old 10-01-2010
Below code could help but only where there are 2 time stamps in the inputfile

Code:
sed -n '/\([0-9][0-9]\/[0-9][0-9]\/[0-9][0-9][0-9][0-9] [0-9][0-9]:[0-9][0-9]\)/,/1/p' inputfile

# 12  
Old 10-01-2010
MySQL grep content between timestamp

Code:
#!/bin/sh
sed -n '/[0-9][0-9]\/[0-9][0-9]\/[0-9][0-9][0-9][0-9]/p' time.txt | sed -e 's/ /./' -e 's/\//./g' > time_stamps.txt
last_time_stamp=`sed -n '$'p time_stamps.txt`
sed -n '/'$last_time_stamp'/,$'p time.txt > last_half_hour.txt
sed -i '1,2d' last_half_hour.txt

Hey Steve,
The Above small script will do ur job...
the file "last_half_hour.txt" will contain the entries for last half an hour...
do some thing to rename "last_half_hour.txt" to your desire.
So when you set this as a cronjob the file won't be overwritten..Smilie
Test it man, it will work for files with any number of time stamps...


Moderator's Comments:
Mod Comment Please use code tags, thank you

Last edited by Franklin52; 10-01-2010 at 12:56 PM..
# 13  
Old 10-01-2010
Hi Kesavan,

Pls telme where you mention the input file in your script?

Thanks

Steve
# 14  
Old 10-01-2010
Bug grep content between timestamp

Quote:
Originally Posted by steve2216
Hi Kesavan,

Pls telme where you mention the input file in your script?

Thanks

Steve
time.txt is the input file........Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep lines between last hour timestamp and current timestamp

So basically I have a log file and each line in this log file starts with a timestamp: MON DD HH:MM:SS SEP 15 07:30:01 I need to grep all the lines between last hour timestamp and current timestamp. Then these lines will be moved to a tmp file from which I will grep for particular strings. ... (1 Reply)
Discussion started by: nms
1 Replies

2. Shell Programming and Scripting

Append timestamp create .trg file for all content of an unzipped archive

Hi, I have a test.zip archive that contains test.zip --> (file_1.txt, file_2.txt , file_3.txt) I need to unzip the file like this, file_1_timestamp.txt file_1_timestamp.trg file_2_timestamp.txt file_2_timestamp.trg file_3_timestamp.txt file_3_timestamp.trg Could you please let me know... (7 Replies)
Discussion started by: Shandel
7 Replies

3. UNIX for Dummies Questions & Answers

Grep content in xml file

I have an xml file with header as below. <Provider xmlns="http://www.xyzx.gov/xyz" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.xyzx.gov/xyz xyz.xsd" SCHEMA_VERSION="2.5" PROVIDER="5"> I want to get the schema version here that is 2.5 and put in a... (7 Replies)
Discussion started by: Ariean
7 Replies

4. Shell Programming and Scripting

How to sort grep result based on timestamp?

Hi, Trying to sort grep result based on timestamp of the filename. I have the following result and want to sort them on timestampgrep -i 'ERROR' *log*2013* s_m_xxx_xxx_xxx_xxx_xxxx.log.20130906092431:TRANSF_1_1_1> DBG_21216 Finished transformations for Source Qualifier . Total errors ... (5 Replies)
Discussion started by: bobbygsk
5 Replies

5. Shell Programming and Scripting

How to grep the content performed by an User

I want to grep the content performed by an User from a file. Suppose that i have a following file HYD-HMS-2$ ls -lrt -rw-r--r-- 1 sdfrun sdf 31726356 Aug 1 13:04 journal.03.01082012.19.csv I could able to grep the content performed by a user by "sed" command as follows HYD-HMS-2$... (0 Replies)
Discussion started by: duppalav
0 Replies

6. Shell Programming and Scripting

how to get tags content by grep

1) Is it possible to get tags content by grep -E ? For example title. Source text "<title>My page<title>"; to print "My page". 2) which bash utility to use when I want to use regex in this format? (?<=title>).*(?=</title) (11 Replies)
Discussion started by: visitor123
11 Replies

7. UNIX for Dummies Questions & Answers

Append file with grep output but add timestamp?

I've setup a cron job that greps a file every five minutes and then writes (appends) the grep output/result to another file: grep "monkey" zoo.log | tail -1 >> cron-zoo-log Is there any way I can add the date and time (timestamp) to the cron-zoo-log file for each time a new line was added? ... (12 Replies)
Discussion started by: Sepia
12 Replies

8. AIX

how to grep and compare timestamp in a file with the current date

I want to read a log file from a particular location.In the log file each line starts with timestamp.I need to compare the timestamp in the logfile with the current date.If the timpestamp in the log file is less than 4 hours then i need to read the file from that location.Below is the file... (1 Reply)
Discussion started by: achu
1 Replies

9. AIX

how to grep and compare timestamp in a file with the current date

I want to read a log file from a particular location.In the logfile , lines contains timestamp.I need to compare the timestamp in the logfile with the current date.If the timpestamp in the log file is less than 4 hours then i need to read the file from that location.Below is the file format.Please... (1 Reply)
Discussion started by: achu
1 Replies

10. Shell Programming and Scripting

how to grep the logs for two particular timestamp

Hi, could anyone help me out how to write a script, to grep the two timestamp from a particular file, so that it will list out all the logs between the particular timestamp I have a pattern of log: servicename operationname starttime endtime eg., servicename1 operationname1 01:11:11... (1 Reply)
Discussion started by: jacktolearn
1 Replies
Login or Register to Ask a Question