472,143 Members | 1,375 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,143 software developers and data experts.

Compare Files and Cat File Difference Question


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
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(NamingCo ntext.java:1414)
at org.jnp.interfaces.NamingContext.lookup(NamingCont ext.java:594)
at org.jnp.interfaces.NamingContext.lookup(NamingCont ext.java:587)
at javax.naming.InitialContext.lookup(InitialContext. java:351)
com.cm.common.util.jndi.MultiJndiLookup.getRemoteO bjectStub(MultiJndiLookup.java:
com.cm.common.util.jndi.MultiJndiLookup.getRemoteO bjectRef(MultiJndiLookup.java:
com.cm.common.util.jndi.JndiLookup.getRemoteObject Ref(JndiLookup.java:
com.cm.system.SystemInfoTopicManager.init(SystemIn foTopicManager.java:
com.cm.system.SystemInfoTopicManager.reconnect(Sys temInfoTopicManager.java:
com.m.system.SystemInfoTopicManager.onException(Sy stemInfoTopicManager.java:
at org.jboss.mq.Connection
$ExceptionListenerRunnable.run(Connection.java:134 8)
at java.lang.Thread.run(Thread.java:595)
Caused by:
at org.jnp.interfaces.NamingContext.getServer(NamingC ontext.java:269)
at org.jnp.interfaces.NamingContext.checkRef(NamingCo ntext.java:1385)
.... 11
2008-10-20 14:59:49,800

Unix diff gives extra output like
< 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:,, ,

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.

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
2008-10-20 14:59:48,828 ...
2008-10-20 14:58:48,900 ...
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
Can this be done with Python quickly ?
Could someone be kind enough to show me steps to accomplish this ?
Any help is appreciated.
Oct 21 '08 #1
0 1558

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Nicolas Fleury | last post: by
2 posts views Thread by RitaG | last post: by
5 posts views Thread by drabee | last post: by
6 posts views Thread by yinglcs | last post: by
3 posts views Thread by super.raddish | last post: by
12 posts views Thread by loial | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.