More log manipulation

wasn't sure if this should have a new thread since I'm still working on the same job I asked a question about earlier. But it's a different problem/question so I guess it deserves a new thread....

I have a log with roughly 10000 lines in it, each one has a timestamp. The problem is, the time is logged in GMT and I need to convert to GMT+10 so I can match the lines up to a corresponding entry in another log which has its timestamps set to EST (GMT+10). Anyone know a way to do this??

Thanks in advance

What is the format of the timestamp ? Give us a sample of how the lines look.

What OS are you on ?

example line from logfile set to GMT:

01/22/2006 05:41:51 10.224.200.235 \\10.176.45.16\live\3x\mtv\co\vid\AdultShop.3gp

Unfortunately the other log set to GMT+10 looks more like :

2006 Jan 23 23:34:09:129 GMT 10 DAACAdapter.DAACAdapter Debug [Adapter] H3G_DAAC
-00000 " Country :505" tracking=#z2oqrqhLxrWoL-Oqd5zzyOzUzzw#

So the date is in a different format (but I'm not worried about that.... at least not yet.) and the time stamps are 10 hours apart. (those two log extracts are not related by the way, they're just examples cut from the different logs.)

Cheers

If your system has GNU date, how about....

$ sed 's/\\/\\\\/g' /var/tmp/logfile | while read date time rest; do
>  timestamp="${date} ${time}";
>  newdate=`date -d "${timestamp} + 10 hours" +"%Y %b %H:%M:%S:00 GMT 10"`;
>  echo "${newdate} ${rest}";
> done

EDIT: Edited to take account of backslashes in input file

Cheers
ZB

Cheers Z

How do I tell if I'm using GNU date?? The response when I run this is

date: illegal option -- d
usage: date [-u] mmddHHMM[[cc]yy][.SS]
date [-u] [+format]
date -a [-]sss[.fff]
10.239.214.212 \\10.176.45.16\live\3x\vws\un\vid\PlayboyM15PromoZGZNR_MP4_AAC_54_8_VQ_L0a_STR.3gp

I'm using SunOS 5.8. I also tried replacing date with /usr/xpg4/bin/date to no avail.

Ah, that'll be no to GNU date then!

Easiest way would be to grab the coreutils package from http://www.sunfreeware.com which contains GNU date.

Or use another method (such as Pederabos datecalc script - search the forums).

Cheers
ZB

Dont worry, I've transferred the logs to another machine and the output of the script looks good, just double checking it now.

Nice one, I hope you boys on here get paid a lot of money :slight_smile: You're definitely worth it!

Cheers

Steve

Zazzybob.... you forgot the %d on the date format!!! Is suppose no-ones perfect. Its nice to know I can work something out at least :slight_smile:

I owe you a beer

here is quick wrapper for datecalc script to get date in YYYYmmdd format

bash> printf '%s%2s%2s' $(./datecalc -a `date +'%Y %m %d'` - 35) | tr ' ' '0'