By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,602 Members | 1,507 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,602 IT Pros & Developers. It's quick & easy.

Compare Files and Cat File Difference Question

P: n/a
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(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)
at
com.cm.common.util.jndi.MultiJndiLookup.getRemoteO bjectStub(MultiJndiLookup.java:
377)
at
com.cm.common.util.jndi.MultiJndiLookup.getRemoteO bjectRef(MultiJndiLookup.java:
130)
at
com.cm.common.util.jndi.JndiLookup.getRemoteObject Ref(JndiLookup.java:
88)
at
com.cm.system.SystemInfoTopicManager.init(SystemIn foTopicManager.java:
91)
at
com.cm.system.SystemInfoTopicManager.reconnect(Sys temInfoTopicManager.java:
181)
at
com.m.system.SystemInfoTopicManager.onException(Sy stemInfoTopicManager.java:
216)
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
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.
Oct 21 '08 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.