How to locate a phrase in a file and read the file after that location

I have a text file with the following contents
Previous date data.....[10,000 lines ]
same as below but with earlier dates
* ABC  AutoJournal Utility - Version 2.00 *
Beginning Reportournal at (time): Tue May 04 18:07:46 IST 2010
AutoJournal assigned updated records a timestamp of (server time):  *2010-05-04*  //THIS IS THE PHRASE  i am looking for
#  Posted Date,           Policy,  Reason, Amount, Insured Name, Agent Name
1) 2010-04-26 00:00:00.0, 7363496, GRSS, 10.0, KRASSNER W, BROOKS STEVEN E
2) 2010-04-23 00:00:00.0, 4768200, GRSS, 0.0, STECKLER M, STECKLER GIBSON
3) 2010-04-20 00:00:00.0, 7328358, GRSS, 4.0, LYON GREGO, WEST MICHAEL J
4) 2010-04-20 00:00:00.0, 4754236, GRSS, 0.0, PEEBLES JA, HOFFMANN GABRIE
5) 2010-04-22 00:00:00.0, 7363793, GRSS, 2.0, LAHAYE NAN, GONYEA MICHAEL
6) 2010-04-26 00:00:00.0, 7360935, GRSS, 35.0, AMITAY NOA, WIESEL HENRYI need to locate the date and start reading the data for the current date only i.e Today's date
Thus far i have done this....
it's just the outline
String srchDate="2010-05-04";
BufferedReader bf=null;
               try {
                      bf = new BufferedReader(new FileReader("C:\\File.log"));
                   int lineID = 0;  
                   Pattern pattern =  Pattern.compile(srchDate);  
                   Matcher matcher = null;  
                   String line =null;
                      while((line=bf.readLine())!=null){ 
                             System.out.println(line);
                                lineID++;  
                                matcher = pattern.matcher(line);      //Will match the entire line against srchDate and will return false ...
                                if( matcher.find()){  
                                    //do stuff...      //stuck here
                                      //get the line no..
                    } catch (Exception e) {
                         e.printStackTrace();
                    }     Some help on this would be very helpful...
Thanks :)
P.S:This needs to be done using java 1,4 only

kevinaworkman wrote:
RainaV wrote:
kevinaworkman wrote:
If I were you, I would split your problem up into smaller pieces.
Write a method that reads a file into a String.This file is actually quiet huge i am not sure if this would work as the file will only grow in size in the future....How big is "quiet huge"? I wouldn't worry about optimization until you've actually encountered a problem.FYI The file size is 20MB ...
>
Write a method that figures out where in a String a substring occurs (hey, that one might be done for you already...).
Write a method that returns a substring of a String, based on a start index and a length (something tells me this one might exist already too).
Write a method that converts a String to the correct datatype.
Regarding these steps i am not sure if i follow>>
the lines you see 1)....
2).... till last line say 800..
I don't understand your question.I was wondering if your appraoch would be complicated but will give it a try...
>
Actually i thght i would just read one complete line and store that in an list and then write it to an excel sheet...Okay, and the steps I outlined would work for reading in one line at a time, as well. It's just one more step.
i am unable to locate this phrase using regex so can you suggest something on that lines
You're trying to find today's date? Why does that require a regular expression?I want to read the data after i have located today's date in the Text file so i need to locate it first but the code i posted doesn't work so i suggested if you can advice on the correction....as per my approach mentioned in the original post
But if i do it your way then definately no need for regex i need to store all of it in a string and work woth sub strings so on,...

Similar Messages

  • Read a csv file and read the fiscal yr in the 4th pos?

    Hello ABAP Experts,
    how to write a code for read a csv file and read the fiscal year in the 4th position.
    any suggestions or code highly appreciated.
    Thanks,
    BWer

    Hi Bwer,
    Declare table itab with the required fields...
    Use GUI UPLOAD to get the contents of the file (say abc.csv) in case if the file is on the presentation server...
    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
        filename                        = 'c:\abc.csv'
       FILETYPE                        = 'ASC'
        WRITE_FIELD_SEPARATOR           = 'X'
      tables
        data_tab                        = itab
    EXCEPTIONS
       FILE_WRITE_ERROR                = 1
       NO_BATCH                        = 2
       OTHERS                          = 22
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    Use OPEN DATASET in case if the file is on the application server..
    After that USE SPLIT command at comma to get the contents of the 4th field...
    Regards,
    Tanveer.
    <b>Please mark helpful answers</b>

  • How do I extract email from a form and send the PDF to that user?

    How do I extract email from a form and send the PDF to that user?

    here you can add email to send to, CC, Subject, and body message
    var oDoc = event.target;
                        oDoc.mailDoc({
                                                                bUI: false,
                                                                cTo: "Agency Contact Email",
                                                                cCC: "",
                                                                cSubject: "Write your title here,
                                                                cMsg: "Dear" + AgencyContact + "(" + AgencyContactEmail + ")\nThe student, " + FirstName + " " + LastName + " has applied to work at your agency. Please confirm they can work here blah blah blah.......\n\nThanks.\n\nrespectuflly,\n\nme"

  • Read from spreedsheet file dont read the file correctly

    Hi, i have the problem that i want to show my voltage output (4 channels) on a graph, by saving the data (the saving process is in a SubVI) on the PC  and reloading it in the mainVI when all actions are done. If i open the file with a editor, like UltraEdit, the data looks right, but on the graph, some parts of the voltage output are shown wrong (as vertical instead of horizontal line)... Anyone got a idea why? or how to fix it?
    Thanks and greetings (and sorry for my bad english ) Mari0
    attached:
    -example voltage output (.lvm)
    -code extract (.vi)
    -picture with wrong parts (.jpg)
    Attachments:
    VoltageOutputReload.vi ‏22 KB
    SignalOutput.txt ‏4044 KB
    New Bitmap Image.jpg ‏1219 KB

    First, let's get the chastizing out of the way:
    Was it really necessary to upload a 4 MB text file as is? Ever hear of compression?
    DO NOT UPLOAD BITMAP FILES OR CHANGE THE EXTENSIONS TO GET AROUND THE BAN ON BITMAPS. THERE IS A REASON THE BAN IS THERE.
    I don't understand what your VI's purpose is. Why are you continuously reading the file in a loop? Is this something you created on the fly for demonstration? If so, the Read From Spreadsheet File needs a True wired to the transpose? input. The graph is showing you exactly what's in the data file. Look at your data. At line 66100 it jumps.
    NOTE HOW I DID NOT UPLOAD A BITMAP.

  • Create unicode file and read unicode file

    Hi
        How can create a unicode file and open unicode file in LV
    Regards
    Madhu

    gmadhu wrote:
    Hi
        How can create a unicode file and open unicode file in LV
    Regards
    Madhu
    In principle you can't. LabVIEW does not support Unicode (yet)! When it will officially support that is a question that I can't answer since I don't know it and as far as I know NI doesn't want to answer.
    So the real question you have to ask first is where and why do you want to read and write Unicode file. And what type of Unicode? Unicode is definitly not just Unicode as Windows has a different notion of Unicode (16 Bit characters) than Unix has (32 Bit characters). The 16 Bit Unicode from Windows is able to cover most languages on this globe but definitly not all without code expansion techniques.
    If you want to do this on Windows and have decided that there is no other way to do what you want you will probably have to access the WideCharToMultiByte() and MultibyteToWideChar() Windows APIs using the Call Library Node in order to convert between 8 bit multybyte strings as used in LabVIEW and the Unicode format necessary in your file.
    Rolf Kalbermatter
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • Read file and store the file into a string

    i want to read the file and copy it to a string.
    i wrote this code but don't know what to do next..
    please help me urgent.....
    File file_to_text = new File("c:\\wtgapp.xml");
    String wtgapp_string=new String();
    try
    BufferedInputStream stream = new BufferedInputStream(new FileInputStream(file_to_text));
    catch (FileNotFoundException file_error)
    JOptionPane.showMessageDialog(null, "FILE READ ERROR", "READ ERROR!",JOptionPane.INFORMATION_MESSAGE );
    System.exit(1);
    }

    BufferedReader reader = new BufferedReader(new FileReader(file_to_text));
    try
    while(reader.readLine() !=)
    wtgapp_string = wtgapp_string+ reader.readLine();
    System.out.println(wtgapp_string);
    i did this..
    but reader.readLine() != null
    didn't work.
    what shoud i write? to go to the end of file
    no it is 16.00pm in here i live in TURKIYE istanbul :)

  • How to use cfdocument  create a PDF file and save the file in server?

    Hi,
    I want to use cfdocument to create a PDF file and save it in
    the server for other people to download,can you give me a idea how
    to do this.Thanks.
    <cfdocument format = "PDF" pagetype="A4"
    orientation="portrait">
    </cfdocument>
    Mark

    Hi
    <cfdocument filename="" format = "PDF" pagetype="A4"
    orientation="portrait">
    </cfdocument>
    Give the physical path to the filename. You have write
    permission for this folder to create a PDF file.

  • Moving files and getting an error after using locate

    I often move files over to external drives to recover space. If I go to a project and get files missing, I then use locate to find the files but when I clcik on the located file I get a file not supported error though it is the same file.

    Yes. If I move the same file back to the original location it loads fine. Actually, I can go back to import and I can import the file from the new location and then replace it in the timeline but that is ridiculous.

  • How  to   download the file and delete the file

    plz send me reply

    Hi Nagalakshmi,
    If you want to download a file on to the presentation server from your application then please have a look at the methods listed under the OO class CL_GUI_FRONTEND_SERVICES from transaction SE24 to perform similar operations as requested by you on files on presentation server.
    However if u are considering downloading and then deleting a file on the application server, then u would need commands like OPEN DATASET, TRANSFER and CLOSE and eventually DELETE DATASET.
    F1 on the commands should help you along.
    Hope this helps.
    Regards,
    Aditya

  • Download a file and give the file name as default name while saving

    Hi folks
    I am facing a problem. I have jsp which fetchs the file name and it's location from the database.
    It can fetch many row's. Now i have provided a radio button, against each row, By clicking on it , the user selects the file to download.
    And clicks on download button, which call an action say "Download File".
    It's downloading the file successfully. But displaying the action name as default name while selecting the location to save the file on local machine.
    I want the file name which he opted to download, should get displayed as default name.

    Set it in the content disposition header.
    The downloadFile() snippet here might give some useful insights: http://balusc.xs4all.nl/srv/dev-jep-pdf.html

  • Save data in a file and email the file

    Dear all,
    I have 2 vi files:
    1. one vi file can store data into a file when it runs and stopped
    2. another vi can send a file out through email when it is run.
    Is it possible for me to run the first vi and stop after one hour (to store data into A file), then run the second vi file and stop (to send A file through email), and then run the first vi again immediately after running the second vi? This is because I need to send out my data saved hourly through email and get my 1st vi to continue running through out the day.
    Due to the file path for my first vi and the second vi are the same, I keep getting error as below when either 1 vi is not stopped.
    Error 5 occurred at Open/Create/Replace File in Write Spreadsheet String.vi->Write To Spreadsheet File (DBL).vi
    Please advice. Thanks.
    Kim

    Dear Ravens,
    I tried to kill (remove) the event structure from my earlier code, but as I run it, I get the same error again- error 5.
    I also tried to put time out value 200 at the timenode at the upper left of the event structure but the email part just never executed.
    I searched thru the forum and found a several examples on state machine as attached. I tried the first attachment for my program but obviously I used the wrong one as you adviced. As for the other state machine examples that I downloaded, I couldn't figure out how to apply them for my case correctly. Can you advcice how can I implement state machine to get the results tat I need?... Pls gv me some clearer hints? 
    Attachments:
    QueuedStateMachineWithEvents.vi ‏49 KB
    StandardStateMachine_2MOD.vi ‏19 KB
    JKI State machine.vi ‏75 KB

  • Need help for Scheduling a Spool file and FTP the file

    I have one requirement like below...
    1. Start Scheduling a job
    2. Generate a Spool file (.csv file)
    3. If Spool file generation is successful then start FTP the file
    Else End job
    4. After successful FTP process end the job.
    We need to create a log file also for this job.
    Can any body give some idea how will i proceed?
    Thanks in advance.

    Billy  Verreynne  wrote:
    BluShadow wrote:
    Chris' may be wrapped, but it includes the funky ability to query remote files directly in SQL due to it's use of pipelined functions. A feature I've also got in my own FTP package and very useful for monitoring logs on remote servers through our Apex applications. ;)Ditto - also rolled my own FTP package as doing wildcard file listing requires custom support depending on the type of FTP server you're dealing with. The text part of the responses differ (these are not RFC'ed) and makes parsing more complex than what it could have been.Yeah, the differing responses can be a pain, though fortunately they are far and few between. There was a bug in Chris' package in that it wasn't handling a two code response from a windows FTP server for one of the commands, but I emailed him and he fixed that. Not his fault, he didn't have a windows FTP server to test on at the time.
    FTP is a pretty straight forward protocol and easy to wrap a PL/SQL package around (using <i>UTL_TCP</i>).Absolutely. and the RFC details almost everthing you need to handle. It was quite quick to knock up a package, similar to the code hoek has linked to.
    I think there is a lot of common stuff that many of us do in this regard. Always wondered how well a proper GPL'ed open source project providing a PL/SQL development framework and libraries would do...I think there'd be a lot of arguments about what is the best way of doing things. :D

  • I have a pdf file attached to email inbox for ipad3.  I also have an neu.Annotate  app for pdf.  Can anyone tell me how to open my pdf through neu.Annotate and save the file?

    How do I save the pdf on ipad3?  How can I view the fiel from neu.Annotate so that I could do the editing from the app?

    If the PDF isn't already downloaded in the email then you should be able to do so by tapping on it.
    If the PDF is open within the body of the email then press and hold it and after a second or so you should get a 'Open In' pop-up; otherwise (e.g. the PDF opens into a separate screen) then tap the PDF and you should get an icon top right of a box with an arrow coming out of it - tap that and you'll get the 'Open In' option

  • How to read the file from ftp server

    Hi
    I need to read a file from a ftp server . Iam using apache lib common-net .jar .
    FTPClient ftp = new FTPClient();
    ftp.connect(server);
    ftp.login(username,password);
    FTPFile[] files = ftp.listFiles();
    for(int i=0 ;i<files.length;i++){
    System.out.println(" File : "+ i + " - " + files);     
    InputStream ip = ftp.retrieveFileStream(path);
    I got the inputstream from the ftp server. but iam not able to read the contents of the file ....
    help me plzzzzz

    Hi
    I have one more problem . first i try to read the file and write the file in local directory . then i try to read the data in the remote file .. iam getting the datas as null.
    InputStream ip = ftp.retrieveFileStream(path);                    
    File f = new File("D:\\ftp.txt");                    
    FileOutputStream fo = new FileOutputStream(f);
    byte[] buf = new byte[1024];
    while ((len = ip.read(buf)) > 0) {                         
    fo.write(buf,0,len);               
    fo.close();
    BufferedReader br = new BufferedReader(new InputStreamReader(ip));
    String line;
    do {
    line = br.readLine();
    System.out.println(" data " +line);
    }while (line != null);

  • VBScript to read the content of a .csv file and delete old files mentioned in the .csv

    I have a Windows 2003 file server.
    I have generated a report in .csv format, about the files which are older than 1 year.
    I need a VBScript to read the .csv file and delete the files which are enlisted there.
    Can someone please help me with this?

    Look into the "Learn" link above.  There are resources and instructions on how to write VBScript code.  Look into how to use the FileSystemObject.
    ¯\_(ツ)_/¯

Maybe you are looking for

  • I am having major Home Sharing issues (disrupting WiFi)

    Have done a lot of research on the particular issues Im having and can only find discussions on problems slightly tangential to mine. Beginning about a week ago whenever I would use home sharing on my iPad or iPhone (streaming through my Mac Pro desk

  • Process Chain with IF condition

    Hi all, It's possibile put in a process chain an IF condition?? This is my problem: I have a process chain that execute  all process even if the result is GREEN or RED. At the end of the chain I have to Make a chois, IF one of the previous step is RE

  • Error java.sql.SQLException

    My patch management update is set to fire off at 2:00am. In my loader-messages.log I have [DEBUG] [7/28/10 2:09:38 AM] [] [ImportContent] [] [Done processing: abaafc6c0bb1427e2fdda82450ff5485] [] [] [DEBUG] [7/28/10 2:09:40 AM] [] [Loader.PatchSubscr

  • ALV cells as buttons

    Hello, I'm using attribute cl_gui_alv_grid=>mc_style_button to put some cells in my ALV as buttons. I need that when the user push those buttons an event is raised. Does someone have any example of buttons in ALV cells? Thank you and regards.

  • I'm trying to log and transfer from a pro res file (HQ) final cut s7 is telling me it is an unsupported format. What the?

    i have a 58 min pro res hq file that is a .mov. it is in a folder on my hdd. i'm trying to syn rushes by logging and transferring clips from this file but i cannot bring the said file into log and transfer. final cut putsup a window that tells me the