Compare Files and Cat File Difference Question

Discussion in 'Python' started by zw, Oct 21, 2008.

  1. zw

    zw Guest

    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.
    zw, Oct 21, 2008
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Yadagiri Rao KP
    Replies:
    3
    Views:
    402
    Joseph Millar
    Aug 9, 2003
  2. Rymfax
    Replies:
    1
    Views:
    492
    Victor Bazarov
    Apr 13, 2007
  3. Sumitava Mukherjee
    Replies:
    4
    Views:
    278
    Tim Roberts
    Oct 21, 2008
  4. Saqib Ali
    Replies:
    9
    Views:
    494
    Michael Torrie
    Jan 16, 2012
  5. Jim

    Cat file a to *.xls files

    Jim, Apr 26, 2007, in forum: Perl Misc
    Replies:
    9
    Views:
    103
Loading...

Share This Page