Separate a file on the basis of timestamp


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Separate a file on the basis of timestamp
# 1  
Old 05-30-2012
Separate a file on the basis of timestamp

hi,

I have a log file which contains data for last 7 seven days.
I want to copy all the data for 6 days in one file and keep only the data for today in that log file and mail that log file containing today's data.

Log file is in this format
Code:
 Time: 120529 10:51:08
 User@Host: local @  [3.210.45.78]  Id: 125684
 Query_time: 0.010631  Lock_time: 0.000044 Rows_sent: 2  Rows_examined: 11
SET timestamp=0000000;

 Time: 120530  5:01:35
 User@Host: local@  [3.247.587.21]  Id: 129386
 Query_time: 63.552782  Lock_time: 0.000051 Rows_sent: 5  Rows_examined: 9
SET timestamp=000000;


please suggest how to separate the entries.

---------- Post updated at 03:01 PM ---------- Previous update was at 02:37 PM ----------

Getting no idea how to do this

suggest some ideas.

Moderator's Comments:
Mod Comment edit by bakunin: please notice, that bumping up questions is against our rules. Furthermore, you posted roughly 30 minutes ago AND ALREADY GET IMPATIENT?? This is not a helpdesk and we are not your employees! There is no obligation for anyone here to answer a certain thread - much less to answer it within some time - and if you don't change your attitude the only thing you might get is some stony silence.

Last edited by bakunin; 05-30-2012 at 06:38 AM.. Reason: Please use code tags
# 2  
Old 05-30-2012
You might probably be interested in this thread where i discussed a very similar problem.

I hope this helps.

bakunin
# 3  
Old 05-30-2012
I want the fragmentation on the basis of timestamp.i.e. data for today will be there and rest copied to some other file. also all the data for that timestamp should come.
Code:
Time: 120524 14:06:06
# User@Host:  @  [5.85.46.21]  Id: 11111111
# Query_time: 0.000564  Lock_time: 0.000056 Rows_sent: 0  Rows_examined: 2
SET timestamp=00000000;

like if it today's date matches with 120524 then all the lines below it should come.i.e user@host, id, query_time lock_time,rows_sent,rows_examined,set timestamp

Moderator's Comments:
Mod Comment edit by bakunin: please use [CODE]..[/CODE]-tags to enclose terminal output and code. It makes the text better readable.

Last edited by bakunin; 05-30-2012 at 07:05 AM..
# 4  
Old 05-30-2012
There is no "timestamp" within a file. Using purely system means it is not possible to decide when a certain entry in a file has been written.

Of course it is possible to have some data in the file which you can interpret as timestamp, like, say, a line "date: 01/01/2000" and you will know that everything following this was later and everything before was earlier. But still you will have to search for that certain pattern, not for a "timestamp", like the "mtime" information of a files last modification time, which is built into the data structure of Unix filesystems.

So take the script part i provided in the mentioned thread, modify it to meet your needs and use it.

I hope this helps.

bakunin
# 5  
Old 05-30-2012
Quote:
Originally Posted by arijitsaha
hi,

I have a log file which contains data for last 7 seven days.
I want to copy all the data for 6 days in one file and keep only the data for today in that log file and mail that log file containing today's data.
Is this what your needs serve for todays match? If YES, then answer and I try to make the last six days match possible.

Code:
awk 'BEGIN{today=strftime("%y%m%d")} ($2 ~ today),/timestamp/' infile >today_to_email.log

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Looping through XML file on basis of a node

<?xml version="1.0" encoding="UTF-8"?> <Document> <FIToFICstmrCdtTrf> <GrpHdr> <MsgId>10001</MsgId> <NbOfTxs>1</NbOfTxs> <IntrBkSttlmDt>2015-05-06</IntrBkSttlmDt> <SttlmInf> <SttlmMtd>CLRG</SttlmMtd> </SttlmInf> <PmtTpInf> ... (2 Replies)
Discussion started by: harish2015
2 Replies

2. Shell Programming and Scripting

Splitting XML file on basis of line number into multiple file

Hi All, I have more than half million lines of XML file , wanted to split in four files in a such a way that top 7 lines should be present in each file on top and bottom line of should be present in each file at bottom. from the 8th line actual record starts and each record contains 15 lines... (14 Replies)
Discussion started by: ajju
14 Replies

3. Shell Programming and Scripting

Script to move file on a daily basis

Hi! Please I need help on the a script that would pick one file in a directory, change its name, them change its permissions, them move to a different directory, but has to be done on a daily basis, and the file that is being moved to its final destination has to have the following format:... (7 Replies)
Discussion started by: fretagi
7 Replies

4. UNIX for Dummies Questions & Answers

Splitting the file basis of Line Number

Can u pls advise the unix command as I have a file which contain the records in the below format 333434 435435 435443 434543 343536 Now the total line count is 89380 , now i want to create a separate I am trying to split my large big file into small bits using the line... (2 Replies)
Discussion started by: punpun66
2 Replies

5. UNIX for Dummies Questions & Answers

How to compare a file by its timestamp and store in a different location whenever timestamp changes?

Hi All, I am new to unix programming. I am trying for a requirement and the requirement goes like this..... I have a test folder. Which tracks log files. After certain time, the log file is getting overwritten by another file (randomly as the time interval is not periodic). I need to preserve... (2 Replies)
Discussion started by: mailsara
2 Replies

6. Shell Programming and Scripting

FTP a file on Hourly basis

Hi, I have to upload a file test_201105281100.txt to a ftp location. The files will be created on hourly basis like test_201105281100.txt, test_201105281200.txt & so on. After a file is uploaded successfully, I need to rename the file as test_201105281100.success & if it is not uploaded... (11 Replies)
Discussion started by: SunilB2011
11 Replies

7. Shell Programming and Scripting

Getting a relative timestamp from timestamp stored in a file

Hi, I've a file in the following format 1999-APR-8 17:31:06 1500 3 45 1999-APR-8 17:31:15 1500 3 45 1999-APR-8 17:31:25 1500 3 45 1999-APR-8 17:31:30 1500 3 45 1999-APR-8 17:31:55 1500 3 45 1999-APR-8 17:32:06 1500 3 ... (1 Reply)
Discussion started by: vaibhavkorde
1 Replies

8. Shell Programming and Scripting

Split one file to Multiple file with report basis in unix

Hi, Please help on this. i want split the below file(11020111.CLT) to more files with some condition. :b: 1) %s stating of the report 2) %e ending of the report example starting of the report: %sAEGONCA| |MUMBAI | :EXPC|N|D ending of the report %eAEGONCA| |MUMBAI | :EXPC 3)so the... (10 Replies)
Discussion started by: krbala1985
10 Replies

9. Shell Programming and Scripting

Separate date timestamp use awk or sed command ?

Hi, I have logfile like this : Actually the format is date format : yyyymmddHHMMSS and i want the log become this format yyyy-mm-dd HH:MM:SS for example 2009-07-19 11:46:52 Can somebody help me ? Thanks in advance (3 Replies)
Discussion started by: justbow
3 Replies

10. Shell Programming and Scripting

sorting of files on the basis of timestamp

Hi, With the help of below script im able to get the count of all the .xml files but that count is not specific to a day ie its the total count of all .xml files what i want is specific to 1 day and that of every half an hr ie from 23 feb 2009 7 am till 23rd feb 2009 2300 am and from 07:00 to... (1 Reply)
Discussion started by: ss_ss
1 Replies
Login or Register to Ask a Question