[solved]how to extract recent log entries from a file (based on time)?

I have a daily log file with hundreds of thousands of entries in the following format. 
field1,field2,field3,field4,field5,field6,field7,field8,field9,20110516192001.100
field1,field2,field3,field4,field5,field6,field7,field8,field9,20110516192002.200
field1,field2,field3,field4,field5,field6,field7,field8,field9,20110516192003.300
field1,field2,field3,field4,field5,field6,field7,field8,field9,20110516192004.400
field1,field2,field3,field4,field5,field6,field7,field8,field9,20110516192005.500
It's always in the same format and the 10th field is always the timestamp (YYYYMMDDHHMMSS.MS)
Since the file rotates daily, the 10th field will always be 20110516xxxxxx.xxx for today and will be 20110517xxxxxx.xxx tomorrow
What I want to do is only look at entries that have been written in the last 30 minutes.
At a high level, here's my plan
1) Get the date/time from 30 minutes ago... write it to a variable
2) Iterate through the file line by line comparing the 10th field to the variable, if it's larger write the line to a tmp file
3) Use tmp file for my analysis
This seems incredibly inefficient to me...  what would be a more graceful way to do it?  I have regular solaris tools at my disposal (plus python)
Thanks
Last edited by oliver (2011-05-17 12:41:43)

The algorith you describe really is a viable approach.  Since this is a log file, each line should have a time stamp later than all lines that preceed it in the file. A more efficient algoithm could do a binary search through the file for the time stamp you are interested in.  This would be easy enough in to do in C or python, but your algoithm could be fast enough. If this is the case, you could try the following quick & dirty bash script.
#!/bin/bash
seconds() {
secs=$(($1 % 100))
mins=$(($1 / 100 % 100))
hrs=$(($1 / 10000 % 100))
days=$(($1 / 1000000 % 100))
month=$(($1 / 100000000 % 100))
year=$(($1 / 10000000000))
(LC_TIME=C date +%s -d $(printf "%d-%02d-%02d %2d:%02d:%02d" $year $month $days $hrs $mins $secs))
found=0
now=$(date +%s)
while read line
do
if [ "$found" -eq "0" ]
then
ts=${line##*,}
ts=$(seconds ${ts%.*})
diff=$(( ($now - $ts)/60 ))
[[ $diff -lt "30" ]] && found=1
fi
[[ $found -ne 0 ]] && echo "$line"
done < $1
It will write (to stdout) all lines following the first line that has been time stamped within the last 30 minutes (ignoring milliseconds). You could redirect the output of this script to a file of your choice for analysis as follows:
$ ./script logfile > tmp
Last edited by rockin turtle (2011-05-17 06:58:41)

Similar Messages

  • How to extract audit log data from every document library in site collection using powershell?

    Hi All,
    I have n number of document library in one site collection,
    My query is- How to extract audit log data from every document library in a site collection using powershell?
    Please give solution as soon as possible?

    Hi inguru,
    For SharePoint audit log data, These data combine together in site collection. So there is no easy way to extract audit log data for document library.
    As a workaround, you can export the site collection audit log data to a CSV file using PowerShell Command, then you can filter the document library audit log data in Excel.
    More information:
    SharePoint 2007 \ 2010 – PowerShell script to get SharePoint audit information:
    http://sharepointhivehints.wordpress.com/2014/04/30/sharepoint-2007-2010-powershell-script-to-get-sharepoint-audit-information/
    Best Regards
    Zhengyu Guo
    TechNet Community Support

  • Cash Management: How to extract unreconciled jrnl entries from gl_je_lines

    Hi,
    Can someone please send me the query to get Unreconciled GL entries from GL for a particular bank account. I want gl_je_lines data which are not yet reconciled with bank statement lines in Cash Management module. If there are gl_je_lines entries which are partially reconciled, I want to send the balance to be reconciled.
    Thanks
    Ranjith

    Hi Ranjith and octavio,
    It was really a learning reading the thread. I am also closely working on a similar activity. I need your help to resolve my issue. Below is the case:
    I need to create a View out of GL_JE_LINES table. This view will have all the journal lines for specific banks (asset_code_combination_id). This activity is basically pre-reconciliation process before the auto reconciliation. So instead of picking all the GL_JE_LINES for the collective asset_code_combination_ids, I would like to ignore those GL LINES which are already reconciled. We could do that with the same methodology you guys have approached. But our problem is that the ce_statement_reconcils_all has rows that does not have JE_HEADER_ID at all. Due to this, we could not compare the JE_HEADER_ID of GL_JE_LINES with reconcils table.
    First in place, what could be the reason that there is no JE_HEADER_ID for some of the rows in CE_STATEMENT_RECONCILS_ALL? Can we ignore those lines in our filter and go head to map those which has JE_HEADER_ID?
    For your information, in CE_STATEMENT_RECONCILS_ALL, for the rows that does not have JE_HEADER_ID, we have ORG_ID.
    Secondly, in CE_STATEMENT_RECONCILS_ALL does the auto reconciliation flag set to N means manual reconciliation done?
    Please help. We are badly looking out for some help since we got stuck at a critical phase of the project.
    Thanks.
    Vijayasarathy R
    Financial Functional
    Chenna, India.

  • How to extract the red layer from BayerRG8 file with VBAI?

    Dear readers,
    We're currentely trying to build a inspection program using a CVS and two cameras.
    A first question to help us: How can we extract the red layer from a Bayer RG8 image?
    To illustrate a lit bit more: lets take a picture of chilis and tomatoes plants. We would like to extract the red color of the picture to know where the vegetable are and if they are eatable.
    So, in a first time, we just want to see the red layer of the picture.
    On a second step, we would like to extract the poistion of the red areas and rank them according to intensities and store all the relevant data in a .txt file.
    Thank in advance for the time you will spend on that topic.
    Regards

    Maybe including a picture with the info you want would help. It sounds like you could use a detect object step (which works with color images), and you could get the position of all red objects. I would also recommend using the Hue plane instead of the Red plane to look for color since this is more robust to lighting changes. Once you have the bounding box for each red object, you can create a programmatic ROI around it and use the Measure Color step to get detailed color information about your reb objects. Here's a sample inspection that uses colored candy to give you an example of what I'm suggesting. Let us know if more specifically what you are looking for if this doesn't help. The example is in VBAI 2012. Let us know what version of VBAI you are using because this may affect what functionality you can use.
    Thanks,
    Brad
    Attachments:
    Color Example.zip ‏358 KB

  • How to delete archive log entries from catalog?

    Some old, not needed archive logs are deleted from disk using OS commands but RMAN catalog still lists them.
    How can I get rid of them in RMAN?

    First mark them expired
    crosscheck archivelog all;then delete them from the RMAN catalog
    delete expired archivelog all;Cheers

  • How to extract audit log from R/3 into BW

    Hi, I have a request that how to extract audit log from r/3 into bw?
    Is there any datasource or infocube  I can use?

    HI ,
    Identify your Audit Log table and create generic data source for the same using rso2. 
    Regards
    BVR

  • Remove a sleep log entry from the Lifelog

    Is it possible to somehow remove a sleep log entry from the Lifelog?
    I have an incorrect entry messing up my average value so I would like to get rid of it.
    Solved!
    Go to Solution.

    It is possible to remove a single sleep activity. You scroll in the timeline to the activity you like to remove, then press the avatar while it’s sleeping. You will get a pop-up with sleep details for this specific sleep activity, press the trash can symbol and remove this activity.
     - Official Sony Xperia Support Staff
    If you're new to our forums make sure that you have read our Discussion guidelines.
    If you want to get in touch with the local support team for your country please visit our contact page.

  • I would like to know how to extract my old contacts from the iTunes backup? Please explain in basic english i am a beginner

    I have had my old Iphone 5s replaced with a new one but I would like to know how to extract my old contacts from the iTunes backup? Please explain in basic english i am a beginner

    Hey,
    I think you will find that you have to have a debit/credit card stored on yur account regardless of whether your have iTunes Credit or want to purchase a free App. I don't know why, I assume its for ID verification or is part of the terms and conditions. I occasionally have to re-verify my credit card info even when just trying to run Update on one of my Apps or like I said downloading a free App.
    If you need further clarification all you can do is contact iTunes Support:
                   https://expresslane.apple.com/ServiceOptionAction.action
    Hope this helps. Andrew

  • How-to extract data in chunks from one R3 to another R3 system

    Does anybody know how to extract data in chunks from one system to another? Imagine you would like to extract 1M records in chunks of 10K records, how would you do it between 2 different R3 systems? A cursor (even with hold) doesn't work
    Any suggestion appreciated
    Thanks
    Ioan

    Hi Ioan,
    I'd do it with fm : TABLE_ENTRIES_GET_VIA_RFC (with where clause-tab)
    or fm GET_TABLE_RFC (get all items)
    regards Andreas

  • TS4062 how do i remove duplicate entries from my phone directory?

    question; how do i remove duplicate entries from my phone directory?

    go to your contacts icon and choose the one you want to delate
    Choose edit, top right and go (scroll) to the bottom of the page and press delete contact

  • Is it possible to remove an action log entry from a ticket?

    Hello.
    Is it possible to remove an actoin log entry from a ticket.  We may run into a situation when confidential data has been pasted into the action log.
    Thank you,
    Richard

    Yes, but not through the UI. the easiest way to do this would be with
    SMLets.
    Import-Module SMLets
    $IRClass = Get-scsmclass Workitem.Incident$
    $SRClass = Get-SCSMClass Workitem.ServiceRequest$
    $ActLogRelationshipClass = get-scsmrelationshipclass System.WorkItem.TroubleTicketHasActionLog
    $IR = Get-SCSMObject -Class $IRClass -Filter "Name -eq 'IR21'"
    $ActionLogs = Get-SCSMRelatedObject -SMObject $IR -Relationship $ActLogRelationshipClass
    Foreach ($ActionLog in $ActionLogs) {
    if ( $ActionLog.Description -match "TEST") {
    Remove-SCSMObject $ActionLog -Force -WhatIf
    It should be noted that this will not remove the action log form the data warehouse. there isn't a supported method to edit data in the DW, so you're kinda on your own if you need to remove this data from the historical records

  • How to Extract data and reports from the SAP BW warehouse

    Hi to All Guru's
    I am new to SAP BW. Can any one help me to know, How to Extract data and reports from SAP BW. Do we use any tools.  After Extracting the data from SAP BW how can we move all the data to Cognos.  It would be kind enough to provide me with any documentation or links.  Step by step procedure would be very much helpfull to me.
    Thanks
    Venu

    Hi Voodi
    Thanks for the quick response. I think Open hub is to extract the data from SAP BW, but what about sending this data into Cognos.  Can you please let me know in detail regarding answer. If possible send me any documentation or links regarding this.  Thanks for your concern.
    Venu

  • How I could transport table entries from table NRIV

    Does anyone knows how I could transport table entries from table NRIV.
    I can mark them in se16 but the "table entries"->"transport" is grey. What shouuld be done.
    Is there another way to transport NRIV entries.
    Thank you in advance

    Hi,
    Goto SE01 -> Create Transport Request.
    Assign the Workbench request/Project.
    Single click the TR. Click on the DISPLAY OBJECT LIST or Press SHIFT + F11.
    Click on CHANGE -> Insert.
    PgmID Obj Object name
    R3TR TABU NRIV
    CLick Extras -> Change Object Function -> All entries.
    Save.
    Release the Tr.
    Best regards,
    Prashant

  • How to  extract  master data  attribute from  r/3 to bw give steps details

    how to  extract  master data  attribute from  r/3 to bw give steps details screenshots

    Hi
    Go through the below process to extract Master Data Attribute from R/3
    Hi,
    Maintaining Generic DataSources
    Use
    Regardless of the application, you can create and maintain generic DataSources for transaction data, master data attributes or texts from any transparent table, database view or SAP Query InfoSet, or using a function module. This allows you to extract data generically.
    Procedure
    Creating Generic DataSources
    1. Select the DataSource type and specify a technical name.
    2. Choose Create.
    The screen for creating a generic DataSource appears.
    3. Choose the application component to which you want to assign the DataSource.
    4. Enter the descriptive texts. You can choose any text.
    5. Select the datasets from which you want to fill the generic DataSource.
    a. Choose Extraction from View if you want to extract data from a transparent table or a database view. Enter the name of the table or the database view.
    After you generate the DataSource, you have a DataSource with an extraction structure that corresponds to the database view or transparent table.
    For more information about creating and maintaining database views and tables, see the ABAP Dictionary Documentation.
    b. Choose Extraction from Query if you want to use a SAP Query InfoSet as the data source. Select the required InfoSet from the InfoSet catalog.
    Notes on Extraction Using SAP Query
    After you generate the DataSource, you have a DataSource with an extraction structure that corresponds to the InfoSet.
    For more information about maintaining the InfoSet, see the System Administration documentation.
    c. Choose Extraction Using FM if you want to extract data using a function module. Enter the function module and extraction structure.
    The data must be transferred by the function module in an interface table E_T_DATA.
    Interface Description and Extraction Process
    For information about the function library, see the ABAP Workbench: Tools documentation.
    d. With texts you also have the option of extracting from fixed values for domains.
    6. Maintain the settings for delta transfer, as required.
    7. Choose Save.
    When performing extraction, note SAP Query: Assigning to a User Group.
    Note when extracting from a transparent table or view:
    If the extraction structure contains a key figure field that references a unit of measure or a currency unit field, this unit field has to be included in the same extraction structure as the key figure field.
    A screen appears on which you can edit the fields of the extraction structure.
    8. Edit the DataSource:
    &#9675; Selection
    When you schedule a data request in the BI scheduler, you can enter the selection criteria for the data transfer. For example, you can determine that data requests are only to apply to data from the previous month.
    If you set the Selection indicator for a field within the extraction structure, the data for this field is transferred in correspondence with the selection criteria in the scheduler.
    &#9675; Hide field
    You set this indicator to exclude an extraction structure field from the data transfer. The field is no longer available in BI when you set the transfer rules or generate the transfer structure.
    &#9675; Inversion
    Reverse postings are possible for customer-defined key figures. Therefore inversion is only active for certain transaction data DataSources. These include DataSources that have a field that is marked as an inversion field, for example, the update mode field in DataSource 0FI_AP_3. If this field has a value, the data records are interpreted as reverse records in BI.
    If you want to carry out a reverse posting for a customer-defined field (key figure), set the Inversion indicator. The value of the key figure is transferred to BI in inverted form (multiplied by –1).
    &#9675; Field only known in exit
    You can enhance data by extending the extraction structure for a DataSource by adding fields in append structures.
    The Field Only Known in Exit indicator is set for the fields of an append structure; by default these fields are not passed to the extractor from the field list and selection table.
    Deselect the Field Only Known in Exit indicator to enable the Service API to pass on the append structure field to the extractor together with the fields of the delivered extract structures in the field list and in the selection table.
    9. Choose DataSource ® Generate.
    The DataSource is saved in the source system.
    Maintaining Generic DataSources
    &#9679; Change DataSource
    To change a generic DataSource, in the initial screen of DataSource maintenance, enter the name of the DataSource and choose Change.
    You can change the assignment of a DataSource to an application component or change the texts of a DataSource. Double-click on the name of the table, view, InfoSet or extraction structure to get to the appropriate maintenance screen. Here you make the changes to add new fields. You can also completely swap transparent tables and database views, though this is not possible with InfoSets. Return to DataSource maintenance and choose Create. The screen for editing a DataSource appears. To save the DataSource in the SAP source system, choose DataSource ® Generate.
    If you want to test extraction in the source system independently of a BI system, choose DataSource ® Test Extraction.
    &#9679; Delta DataSource
    On the Change Generic DataSource screen, you can delete any DataSources that are no longer relevant. If you are extracting data from an InfoSet, delete the corresponding query. If you want to delete a DataSource, make sure it is not connected to a BI system.
    NR

  • How to extract the contents of the Jar file?

    Hello,
    Can anyone tell me how to extract the contents of the Jar file?
    An example will be highly appreciated.
    Thanks.

    From command line, or from within a java application?
    Kaj
    Btw. Why do you need to do it. You do know that you can add jars to the classpath and read resources from them without extracting the file?

Maybe you are looking for

  • Several Payment Methods in VA01

    Hello all Does anyone know if we can have several payment methods in a sales order? When I create a sales order (VA01) I could choose one payment method, but if a customer pays for example 50% with cash and the other 50% with a credit card, Could I e

  • I am unable to import photos into I Photo from my Kodak Z700  camera. any solutions?

    I have tried over and over again to import photos from my Kodak Z700 camera intoI Photo.  I keep getting the essage that the format is incorrect.  Any Solutions?

  • Lightroom 2 won't install on my macbook pro w/ mavericks. any suggestions?

    i get an error message when i try to install lightroom2 on my macbook pro. it just about completes the process and when it starts to finalize it quits and says contact adobe.

  • Empties Management

    Hi Experts, Can any one help me by sending a document which explains about the "Configuration Settings" as well as "Business Process" about  "Empties Management" which is a new functionality  in ECC 6.0 Version. Thanks in Advance G G Prasad.

  • Regarding BI Applications flow

    Hi Gurus, I am at the point that i have installed BI Applications, integrated DAC with informatica and i am able to run few ETLs using Universal Adaptors, Everything is running fine, when i login to presentation services all the dashboards are null o