How to catch date and time from log files?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to catch date and time from log files?
# 1  
Old 06-15-2011
How to catch date and time from log files?

Hi,

Appli.log files contain the below data which updates continuously

================================================== ===============


Tuple Created OrderEntry|66|39.0|ADML.L|16.89|GBP||GFD|000002889 41ORLO1|GB00B02J6398|80|XLON|UHORIZON|null|2011-05-09 17:14:59.241+0000|UHORIZON||null|LIM|null|1


Tuple Created OrderEntry|83|10.0|ISA.L|6.355|GBP||GFD|0000028894 3ORLO1|GB00B09LSH68|80|XLON|UHORIZON|null|2011-05-09 17:29:53.339+0000|UHORIZON||null|LIM|null|1

Tuple Created OrderEntry|83|100.0|MSFT.O|0.0|USD|RICHU|GFD|00000 288946ORLO1|US5949181045|65|XNAS|DMA_FIXIN|null|20 11-05-09 17:45:14.280+0000|UHORIZON||null|LIM
.
.
.
.
.
.
.
.

file update continuously

================================================== =============

from above data ...
i want to catch the date and time differntly means

date contains only the data---->2011-05-09
time .....>17:14:59



$Date=2011-05-09
$Time=17:14:59


please help me to catch this date and time

Thanks in advance....


Regards,
Priyanka
# 2  
Old 06-15-2011
Code:
bash-3.00$ nawk -F"\|" '{date=substr($15,1,10); time=substr($15,12,8);print date,time}' /tmp/myfile
2011-05-09 17:14:59

# 3  
Old 06-15-2011
Assuming you want the last record in the file.

Code:
Date=`tail -1 filename|cut -d\| -f15|awk ' { print $1 } '`
Time=`tail -1 filename|cut -d\| -f15|awk ' { print substr($2,1,8) } '`

# 4  
Old 06-15-2011
Given requirement does not look precise. If you just need last updated date then use tail command along with sed command. The below would fetch all the available date and time patterns from your log file assign it to the respective variables..
Code:
time=$(sed 's/.*|[^|]* \([0-9:]*\).*/\1/' inputfile)
date=$(sed 's/.*|\([0-9-]*\) .*/\1/' inputfile)

This User Gave Thanks to michaelrozar17 For This Post:
# 5  
Old 06-15-2011
we all missing a point here, if the file is continuously updated then there is no guarantee that the last record will be full (with all fields of our assumption) it may contain just one char or few chars.

So we need make check that the last record is full by checking the number of fields. If it is full then take necessary date and time.
# 6  
Old 06-15-2011
Hi,

Thanks to all ,

actully my final aim is to display the output like below-

date:2011-05-09

Time:
17:14:59
17:29:53
17:45:14
.
.
.
.
# 7  
Old 06-15-2011
you mean for each date you want to display the times of records ?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Comparing files by date/time

I am trying to compare identically named files in different directories and replace a file only with a newer version. Is there a way of doing this? TIA (4 Replies)
Discussion started by: wbport
4 Replies

2. Shell Programming and Scripting

Files with date and time stamp

Hi Folks, Need a clarification on files with date and time stamp. Here is my requirement. There is a file created everyday with the following format "file.txt.YYYYMMDDHHMMSS". Now i need to check for this file and if it is available then i need to do some task to the file. I tried... (6 Replies)
Discussion started by: jayadanabalan
6 Replies

3. Shell Programming and Scripting

Extracting log files based on date and time.

Hi All, i have some log files generated in a folder daily with the format abc.def.20130306.100001 ghi.jkl.20130306.100203 abc.def.20130305.100001 ghi.jkl.20130305.100203 the format is the date followed by time . all i want is to get the files that are generated for todays... (3 Replies)
Discussion started by: mahesh300182
3 Replies

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

5. Shell Programming and Scripting

How can view log messages between two time frame from /var/log/message or any type of log files

How can view log messages between two time frame from /var/log/message or any type of log files. when logfiles are very big and especially many messages with in few minutes, I would like to display log messages between 5 minute interval. Could you pls give me the command? (1 Reply)
Discussion started by: johnveslin
1 Replies

6. UNIX for Dummies Questions & Answers

Adding date and time to a log file

Morning all Im hoping you can help me. We have a nice new oracle server :( and are needing to move some files around for EDI and BACS. The server runs windows but has an app called MKS toolkit installed which give unix commands. (Needed for the oracle stuff) I have had a go using dos commands... (2 Replies)
Discussion started by: ltodd2
2 Replies

7. Shell Programming and Scripting

Processing a log file based on date/time input and the date/time on the log file

Hi, I'm trying to accomplish the following and would like some suggestions or possible bash script examples that may work I have a directory that has a list of log files that's periodically dumped from a script that is crontab that are rotated 4 generations. There will be a time stamp that is... (4 Replies)
Discussion started by: primp
4 Replies

8. UNIX for Dummies Questions & Answers

List files with date and time stamps only

Hi there, I'm using terminal on mac and using the ls -l command to list all the files in a directory. However, I only want to display the date and time stamp of each file rather than permissions, owner, group etc... Is this possible? Many thanks in advance Dave (2 Replies)
Discussion started by: davewg
2 Replies

9. Shell Programming and Scripting

Date and time log file

Hi, I wrote a small perl script in unix that searches in a file and saves some information in a separate file. Since this is a log file, I would like to have the date added to file name. I have no idea where to start. output: log_010907.txt thanks ken (8 Replies)
Discussion started by: captoro
8 Replies

10. UNIX for Dummies Questions & Answers

Comparing files named by date/time

I've looked at several of the previous posts and can't seem to find any that pertain to my problem, I'd appreciate some help if possible. I have a directory with numerous logs of various names all named by heading and date ie. dog.20050529.log dog.20050530.log ... (2 Replies)
Discussion started by: gillr
2 Replies
Login or Register to Ask a Question