Compare Files and Cat File Difference Question

Z

zw

Hi

I have 2 log files, each with a timestamp on the first 2 fields.
However, when I do a
awk '/ / {print $1,$2}' logs/x.log
on a log file,

it is complicated by the fact that I also get other non timestamp
column,
2008-10-20 15:00:06,113
2008-10-20 15:00:06,113
2008-10-20 14:59:48,828
javax.naming.CommunicationException: Could
at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1414)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:594)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
at javax.naming.InitialContext.lookup(InitialContext.java:351)
at
com.cm.common.util.jndi.MultiJndiLookup.getRemoteObjectStub(MultiJndiLookup.java:
377)
at
com.cm.common.util.jndi.MultiJndiLookup.getRemoteObjectRef(MultiJndiLookup.java:
130)
at
com.cm.common.util.jndi.JndiLookup.getRemoteObjectRef(JndiLookup.java:
88)
at
com.cm.system.SystemInfoTopicManager.init(SystemInfoTopicManager.java:
91)
at
com.cm.system.SystemInfoTopicManager.reconnect(SystemInfoTopicManager.java:
181)
at
com.m.system.SystemInfoTopicManager.onException(SystemInfoTopicManager.java:
216)
at org.jboss.mq.Connection
$ExceptionListenerRunnable.run(Connection.java:1348)
at java.lang.Thread.run(Thread.java:595)
Caused by:
at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:269)
at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1385)
.... 11
2008-10-20 14:59:49,800

Unix diff gives extra output like
1,38c1,2
< 2008-10-20 15:00:09,890 WARN [trans2@D-CM-TRLOAD04:***:***:***]
[ExceptionListener Connection@
323[token=ConnectionToken:ID:93/1003454235 rcvstate=STARTED]]
com.cm.system.SystemInfoTopicManager - Jms server not reachable..it
may be down. Deatils:Could not obtain
connection to any of these urls:
172.16.70.1:1100,172.16.70.2:1100,172.16.70.3:1100,172.16.70.4:1
100,172.16.70.5:1100

I like to generate a 3rd file after comparing 2 files with format like
the other 2 files but containing only the difference between 1st and
2nd files.
ie

suppose the file contains
file1 file2
2008-10-20 15:00:06,113 ... 2008-10-20
15:00:06,113 ...
2008-10-20 15:00:06,113 ... 2008-10-20
15:00:06,113
2008-10-20 14:59:48,828 ...
2008-10-20 14:58:48,900 ...
javax.naming.CommunicationException...
at org.jnp.interfaces.NamingContext.ch...

I'm hoping to get in file3
2008-10-20 14:59:48,828 ...plus rest of line
2008-10-20 14:58:48,900 ...plus rest of line

I suppose I also need to read in the 1 field of the timestamp and
convert time to unix time to compare and then convert that unix time
to this timestamp format.

It looks like filecmp.cmp isn't enough to cope with my requirements
cuz it only gives a boolean value of 0 or 1,
not the actual print out of the differences between 2 files into a new
file.
Can this be done with Python quickly ?
Could someone be kind enough to show me steps to accomplish this ?


Any help is appreciated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top