Specific text file parsing

Hello.
Anyone have an idea how to parse txt file in format
[2014-12-27 20:44:02] Server->request : Array
    [login] => 1111111
    [date] => 2014-12-29
    [dealid] => 111111111
    [details] => Array
            [Exception] => Array
                    [field] => Array
                              [errors] =>
Array
                                   [error]
=> Array
[code] => 15896
[description] =>not possible

Its multiple sequences
[2014-12-27 20:44:02] Server->request : Array
[2014-12-27 20:50:01] Server->request : Array
I need to get date
[2014-12-27 20:44:02], login [login] => 1111111, and err code  [code] => 15896

Similar Messages

  • Text file parsing and output

    Hi,
    I'm extremely new to Java and need to read and parse a text file and generate a new text file with modifications as follows:
    1. Ignore and rewrite comments
    2. Ignore and rewrite compiler commands
    3. (a) Modify function prototypes be removing their return values, if any,
    (b) append an '_VAR' to the function name and args
    (c) add an ampersand to the args when passed by reference
    sample input file:
    /***** comment *****/
    #if (INCLUDE_STATIC_BUILD == OS_FALSE)
    extern OS_MEMORY_POOL *MEM_Non_Cached;
    #endif
    UINT16 TLS_IP_Check (const UINT16 *s, UINT16 len);
    INT32 MEM_Copy_Data(NET_BUFFER buf_ptr, const CHAR HUGE buffer, INT32 numbytes, UINT16 flags);
    sample output file:
    /***** comment *****/
    #if (INCLUDE_STATIC_BUILD == OS_FALSE)
    extern OS_MEMORY_POOL *MEM_Non_Cached;
    #endif
    UINT16_VAR = TLS_IP_Check (&UINT16_VAR, UINT16_VAR);
    INT32_VAR = MEM_Copy_Data(&NET_BUFFER_VAR, name, INT32_VAR, UINT16_VAR);
    I would appreciate any help!
    Thanks.

    Check replies on the other post
    http://forum.java.sun.com/thread.jspa?threadID=680728&tstart=0

  • Text file parsing

    hi everybody
    I am creating a application in which i am reading a text file from resource and using this text in my canvas but i am facing problem in fetching some characters like currency sign like euro in text and some other characters that are not in normal character set so how can i use these in my application.
    Message was edited by:
    nj_java

    search on this forum, we had few weeks ago a discussion on chinese encoding...
    it could be the same answers.

  • Writing To A Specific Text File Line

    In a program I am writing I need to be able to write to the end of a specific line in a textfile. I'm not sure of any particular way to do this apart from perhaps rewriting the whole textfile which would be a pain to do. Does anyone know of a simpler way of how to do this?

    RandomAccessFile would help somewhat; with it you could overwrite at a given location by moving the file pointer. The problem with this is it still doesn't solve your case, which is appending. Files are essentially large arrays of data, so you can't easily insert data in the middle of it without having to rewrite the remaining portion of the file.

  • Find Change through external text file

    Hello folks
    I am bit pretty in InDesign scripting so could you please look into this.
    How can i change any particular text field in Indesign CS3 document from text file.
    I do have find change script but for each InDesign document specific text file is assigned.
    So each time i have to modify find change GREP property that is also repetetive of work. Is there any way to get find change information should be extract from external text file.
    Many Tanks in advance

    In the FindChangeByList script, you could customize the function myFindFile(myFilePath) {...} as to search the FindChangeList text file in the document location rather than the script location. That's an example. The question is: given a document, where will you have the corresponding FindChangeList?
    @+
    Marc

  • Use AppleScript or Automator (or both) to get Mail and add to a text file?

    Hello all,
    I'm sorry if this is a duplicate of a well-known topic, I tried searching and couldn't see anything.
    I'm behind a proxy at work that blocks any kind of webmail access, but I'd like to be able to check my email while on a break or something.
    I had the idea that I could use Automator or Applescript to check my mail, get the new messages and add the text to a textfile that I could host on my personal webserver that I use for family stuff.
    I've tried an automator workflow that seems to work while in Automator, but when I save it as an application, it won't even start Mail to check.
    I also thought of just leaving mail running, and have a rule that starts a script when new mail arrives, but I don't know enough about Applescript to do it.
    I don't want to confuse anyone with the details of my convoluted ideas, so I'll leave it at that.
    Is there a way to do this? I want mail to check the server, download the messages, new messages get their text appended to a text file that's stored in my webserver's directory (same computer) that I can access from the web, and have it repeat every 5 minutes or so.
    If I've left out a detail, let me know, and if I'm just stupid and there's an easy way to do this... be kind.
    Thanks!
    aeix
    iMac G5 2.0 GHz   Mac OS X (10.4.6)  

    It certainly is going in the right direction. I'm not all that versed in AppleScript, but it looks like that particular script is creating a new text file for every message processed.
    I would like to either create a specific text file if it doesn't exist, or append the text to the end of the file if it does exist.
    But like I said, definitely heading in the right direction!
    iMac G5 2.0 GHz Mac OS X (10.4.6)

  • Parse large (2GB) text file

    Hi all,
    I would like your expert tips on efficient ways (speed and memory considerations) for parsing large text files (~2GB) in Java.
    Specifically, the text files in hand contain mobility traces that I need to process. Traces have a predefined format, and each trace is given on a new line in the text file.
    To obtain the attribues of each trace i use java.util.regex.Pattern and java.util.regex.Matcher.
    Thanks in advance,
    Nick

    Memory mapped files are faster when you need random access and you don't need to load all the data, however here it just add complexity you don't need IMHO.
    I suspect most of the time is taken by the parser so if you customise your parser it could be faster. Here is a simple custom parser
    public static void main(String... args) throws IOException {
        String template = "tr at %.1f \"$obj(1) pos 123.20 270.98 0.0 2.4\"%n";
        File file = new File("/tmp/deleteme.txt");
    //        if(!file.exists()) {
            System.out.println(new Date()+": Writing to "+file);
            PrintWriter pw = new PrintWriter(file);
            for(int i=0;i<Integer.MAX_VALUE/template.length();i++)
                pw.printf(template, i/10.0);
            pw.close();
            System.out.println(new Date()+": ... finished writing to " + file + " length= " + file.length() / 1024 / 1024 + " MB.");
        long start = System.nanoTime();
        final BufferedReader br = new BufferedReader(new FileReader(file), 64 * 1024);
        for(String line;(line = br.readLine()) != null;) {
            int pos = 6;
            int end = line.indexOf(' ', pos);
            double time = Double.parseDouble(line.substring(pos, end));
            pos = line.indexOf('s', end+12)+2;
            end = line.indexOf(' ', pos+1);
            double x = Double.parseDouble(line.substring(pos, end));
            pos = end+1;
            end = line.indexOf(' ', pos+1);
            double y = Double.parseDouble(line.substring(pos, end));
            pos = end+1;
            end = line.indexOf(' ', pos+1);
            double z = Double.parseDouble(line.substring(pos, end));
            pos = end+1;
            end = line.indexOf('"', pos+1);
            double velocity = Double.parseDouble(line.substring(pos, end));
        br.close();
        long time = System.nanoTime() - start;
        System.out.printf(new Date()+": Took %,f sec to read %s%n", time / 1e9, file.toString());
    {code}
    prints
    {code}
    Sun May 08 09:38:02 BST 2011: Writing to /tmp/deleteme.txt
    Sun May 08 09:42:15 BST 2011: ... finished writing to /tmp/deleteme.txt length= 2208 MB.
    Sun May 08 09:43:21 BST 2011: Took 66.610883 sec to read /tmp/deleteme.txt
    {code}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Using a scanner to parse a text file

    Hi,
    I'm running into some difficulties using a pattern for my scanner (java.util.Scanner). I need to scan a text file which consists of records. Each record has a keyword and a value (like property files):
    Example:
    FACILITY=TEST
    LOT=1234567
    DEVICE=abcdefgNormally, every record will be ended by a carriage return and line feed. So what I did was using a scanner with cr/lf as delimiter. That worked fine for most records but there are some records which span several lines (with cr/lf at the end of each line), e.g.:
    MAP_XY.01.01=" Y-7 24/10 Y-6 24 22/17 15/7 Y-5 29/7 5 Y-4 32/22 20
    19/15 13/4 Y-3 34/24 22/13 11/2 Y-2 36/30 28/24 22
    21/12 10/4 2/0 Y-1 38/0 Y0 40/35 33/22 20/15 13/0 Y1 41
    40/32 30/8 6/-1 Y2 42/26 24/-2 Y3 42/-5 Y4 47/11 9
    8/3 1/-6 Y5 48/47 45/39 37/18 16/-7 Y6 49/8 6/-8 Y7 49
    47/8 6/4 2/-8 Y8 50/9 7/3 1/-9 Y9 51/11 9/-10 Y10 51
    50/33 31/-10 Y11 52/40 38/35 33/23 21/16 14/-11 Y12 52
    51/34 32/15 13/4 2/-11 Y13 53/40 38/35 33/-12 Y14 53
    52/35 33/27 25/18 16/13 11/9 7 5 2/0 -4/-12 Y15 53
    52/-12 Y16 53/22 20/-5 -7/-13 Y17 54/47 45/-7 -9/-13 Y18 54
    53/22 20 18/2 0/-13 Y19 55/16 14/13 11/-2 -4/-13 Y20 55
    53/41 39/35 33/-14 Y21 55/52 50/48 46/16 14/10 8/-2 -4
    -6/-14 Y22 54/33 31/7 5/4 2/0 -2/-9 -11/-13 Y23 55
    54/53 51/26 24/-2 -4/-13 Y24 55/15 13/-14 Y25 55 53
    52/-7 -9/-10 -12/-14 Y26 54/44 42/14 12/10 8/-4 -6
    -7/-10 -12/-13 Y27 55/52 50/23 20/16 14/-13 Y28 54
    53/12 10/-1 -3/-13 Y29 55/44 42/-13 Y30 55/15 13/10 8
    7/-13 Y31 55/17 15/-13 Y32 54/44 42/-1 -3/-13 Y33 54
    53/41 39/30 28/-13 Y34 54 52/37 35/19 17/12 9/8 5/3 1
    0/-4 -6 -9/-11 Y35 54/-13 Y36 54/35 33/31 29/13 11
    10/2 0/-2 -4/-13 Y37 54/-13 Y38 53/11 9/0 -2/-9 -11
    -12 Y39 53/35 33/31 29/-12 Y40 53/22 20/15 13/-12 Y41 52
    50/15 13/10 8/-11 Y42 52/11 9/5 3/-6 -8/-11 Y43 51
    50/41 39/10 8/0 -2/-10 Y44 51/28 26 24/15 13/12 10
    9/-10 Y45 50/43 41/32 30/4 2/-9 Y46 49/31 29/13 11
    10/-8 Y47 49/47 45/30 28/24 22/-8 Y48 48/42 40 38/12 10
    9/-7 Y49 47/42 40/38 36/-6 Y50 44/33 31/30 28/6 4/-5 Y51 44
    43/28 26/17 15/13 11/-2 Y52 44/32 30/-2 Y53 43/32 30
    29/13 11/-2 Y54 42/27 25/24 22/16 9 7/-1 Y55 41/21 19
    18/0 Y56 39/15 13/6 4 2 Y57 38/20 18/3 Y58 36/5 Y59 34
    33 31/30 28/7 Y60 31/28 26/10 Y61 27/14"
    BIN_COUNT.01.09=12345Using the following delimiter does not work
    fileScanner.useDelimiter("\\s*=\\s*");because the result would be something like:
    keyword: FACILITY     value: TEST
    LOTkeyword: 1234567
    DEVICE     value: abcdefgWhat I need is a pattern which also handles carriage return/line feed until a new keyword (like LOT for example) occurs.
    The correct result should be:
    keyword: FACILITY     value: TEST
    keyword: LOT            value: 1234567
    keyword: DEVICE     value: abcdefg
    keyword: MAP_XY.01.01 value: " Y-7 24/10 Y-6 24 22/17 15/7 Y-5 29/7 5 Y-4 32/22 20...
    {code}
    I hope, I did explain clearly enough...
    Any help would be appreciated.
    Thanks and best regards
    - Stephan                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Any help would be appreciated.You have grouping and data in the groupings and you are attempting to parse it all at one go.
    Won't work. (Might in a perfect world but not in this one.)
    You need a parsers that do the following
    1. Parser text file (stream) into records.
    2. Parse records into data.
    You can put both into one class or not.
    Your record parser is going to be based roughly on the following scheme.
    1. Find keyword,
    2. Look up format defined for keyword
    3. Attempt to read format found.
    4. Error if format not found.
    5. Else return the record found.
    I say roughly because as noted above you need to know what the actual output looks like. It is possible to determine this if you have enough examples but it is a lot easier if you actually get the specification that tells you what it looks like.
    I suspect, but don't know that the "format" in the above will consist of the following.
    <word><text>
    or
    <word><text>
    <space><text>
    <space><text>
    You could just create one format for the all but you will likely have record types that don't fit that and the earlier you detect errors the better.

  • Can I add specific text to Template via pop up text box on opening file?

    In most word processors it is possible to create a template that asks you for specific text when you open it, so that you can have the letter three quarters written within the template, and only need to replace names, addresses, date and so on.
    In Lotus WordPro for instance, before I even see the file, I have to fill in a dialogue box with the persons name, the subject of the letter, and four or five specifics unique to them. The WP then adds this info into the letter, and all I need do is to occasionally write a further full paragraph.
    How do I do this in Pages? I can't seem to find anyway to do it at all. I have a suspicion I might need Apple Script, but I'm not sure how I can do that. I have a book of how to code, but I don't know where to store the macro, nor to write it yet - the book's just there if I need it.
    I want to open the file, and then be asked one item at a time for the personalised answers to questions that occur in every report/letter.
    Any ideas?
    TIA
    Mac

    Thanks for your suggestions, Magnus, you really have had a good think for me - I appreciate that!
    What I am doing is report writing in which 90% of the report is the same for everyone. Except the cover page with Name and Address details, and Report title; the initial section which is the same for everyone except for specifics such as amount to invest, reason for investment, term to invest over, things like that.
    The end of the report is the recommendations section which is where I use freetext to create a bespoke solution - this cannot be automated.
    Just automating the cover page and the intro section save me huge amounts of time which I can then use on research and fund analysis, leaving the principles of investment section pretty much the same for everyone, as here I'm describing the principle and theory.
    After I created this Report Template my average report creation time went down from about 3 to 4 hours, to about 45 minutes. I guess the automation itself doesn't save as much time as the templating does, but it allows me to concentrate on the important bit and not worry if I have left something out - or in - that changes the overall thrust of the report.
    I cannot load Lotus WorpPro on Parallels, nor on Virtual PC, so the lack of automation really is a pain here. I see it as a weakness of Apple products for business, as I am sure Microsoft do which is why they have dropped VBA support for Office 2008.
    I have got NeoOffice as well as OpenOffice for Mac on my system, but really they aren't atable enough to use, and the formatting is pretty flaky. It certainly isn't completely consistent with Office itself.
    So, I am left with the conclusion that progress only means a reduction in features!
    But maybe I'm missing something?
    Mac

  • How to retrieve specific data from a text file

    Hi, everyone
    For my project it is required that a parameter file is read at the beginning, in order for certain variables to be initialized with specific values that change with the user.
    At the moment, the way it is done is the following:  The values at a specified sequence in a text file are read and saved in an array and the elements of the array are retrieved according to their index.
    The problem with this implementation is, that if for some reason the format of the file changes, e.g. we want to use a parameter file from a previous version of the program that has the values for the same variables but in a different order, the only way to have the right values for the parameters is to change everything accordingly, which is really time wasting.
    Could someone suggest a different implementation that would make the reading of the different values independent from their order in the file, e.g. by scanning the file for specific strings and reading the value after the string?
    Thank you very much.
    P.S. I have  attached a screenshot of the routine I am using now.
    Solved!
    Go to Solution.
    Attachments:
    read parameter file.JPG ‏180 KB

    Hi panagiov,
    Find attached Folders.
    Method 1: in this you can search for each variable separately. You can use "Config file vis" to get all keys(Variables) at once and then you can use for loop to get their values. Or you can access individual values as shown in this code.
    Method 2: here you will get all data at once. You will get Variable and Data (2D array) You need to search variables as and when required.
    I hope you will understand these methods.
    Best of luck
    Gaurav k
    CLD Certified !!!!!
    Do not forget to Mark solution and to give Kudo if problem is solved.
    Attachments:
    Method 1.zip ‏7 KB
    Method 2.zip ‏9 KB

  • How to parse data from a text file with no convenient delimiters?

    I need to read data from a text file.  This file contains one line of data with the repeating pattern "time 00 ADVar2: ___ Height: ____ time 01 ADVar2: ___ Height: ___ ..."  I need LabView to parse out the "time" and "height" values, build an array with the values, and graph the correlation on an X&Y plot.  Does Labview have an automated way to read to the input data file and parse out the correct values, even without convenient delimiters?  Thank you.

    You actually do have a convenient delimiter: "time". Thus, you can make an array using that as the delimiter. Only caveat is that the first array element will be empty. Then you can conveniently use the Scan From String function in a for-loop. Something like this:
    Message Edited by smercurio_fc on 11-21-2008 03:13 PM
    Attachments:
    Example_VI.png ‏9 KB

  • How can i read all the lines from a text file in specific places and use the data ?

    string[] lines = File.ReadAllLines(@"c:\wmiclasses\wmiclasses1.txt");
    for (int i = 0; i < lines.Length; i++)
    if (lines[i].StartsWith("ComboBox"))
    And this is how the text file content look like:
    ComboBox Name cmbxOption
    Classes Win32_1394Controller
    Classes Win32_1394ControllerDevice
    ComboBox Name cmbxStorage
    Classes Win32_LogicalFileSecuritySetting
    Classes Win32_TapeDrive
    What i need to do is some things:
    1. Each time the line start with ComboBox then to get only the ComboBox name from the line for example cmbxOption.
       Since i have already this ComboBoxes in my form1 designer i need to identify where the cmbxOption start and end and when the next ComboBox start cmbxStorage.
    2. To get all the lines of the current ComboBox for example this lines belong to cmbxOption:
    Classes Win32_1394Controller
    Classes Win32_1394ControllerDevice
    3. To create from each line a Key and Value for example from the line:
    Classes Win32_1394Controller
    Then the key will be Win32_1394Controller and the value will be only 1394Controller
    Then the second line key Win32_1394ControllerDevice and value only 1394ControllerDevice
    4. To add to the correct belonging ComboBox only the value 1394Controller.
    5. To make that when i select in the ComboBox for example in cmbxOption the item 1394Controller it will act like i selected Win32_1394Controller.
    For example in this event:
    private void cmbxOption_SelectedIndexChanged(object sender, EventArgs e)
    InsertInfo(cmbxOption.SelectedItem.ToString(), ref lstDisplayHardware, chkHardware.Checked);
    In need that the SelectedItem will be Win32_1394Controller but the user will see in the cmbxOption only 1394Controller without the Win32_
    This is the start of the method InsertInfo
    private void InsertInfo(string Key, ref ListView lst, bool DontInsertNull)
    That's why i need that the Key will be Win32_1394Controller but i want that the user will see in the ComboBox only 1394Controller without the Win32_

    Hello,
    Here is a running start on getting specific lines in the case lines starting with ComboBox. I took your data and placed it into a text file named TextFile1.txt in the bin\debug folder. Code below was done in
    a console app.
    using System;
    using System.IO;
    using System.Linq;
    namespace ConsoleApplication1
    internal class Program
    private static void Main(string[] args)
    var result =
    from T in File.ReadAllLines(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "TextFile1.txt"))
    .Select((line, index) => new { Line = line, Index = index })
    .Where((s) => s.Line.StartsWith("ComboBox"))
    select T
    ).ToList();
    if (result.Count > 0)
    foreach (var item in result)
    Console.WriteLine("Line: {0} Data: {1}", item.Index, item.Line);
    Console.ReadLine();
    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my webpage under my profile but do not reply to forum questions.

  • How can I use Automator to extract specific Data from a text file?

    I have several hundred text files that contain a bunch of information. I only need six values from each file and ideally I need them as columns in an excel file.
    How can I use Automator to extract specific Data from the text files and either create a new text file or excel file with the info? I have looked all over but can't find a solution. If anyone could please help I would be eternally grateful!!! If there is another, better solution than automator, please let me know!
    Example of File Contents:
    Link Time =
    DD/MMM/YYYY
    Random
    Text
    161 179
    bytes of CODE    memory (+                68 range fill )
    16 789
    bytes of DATA    memory (+    59 absolute )
    1 875
    bytes of XDATA   memory (+ 1 855 absolute )
    90 783
    bytes of FARCODE memory
    What I would like to have as a final file:
    EXCEL COLUMN1
    Column 2
    Column3
    Column4
    Column5
    Column6
    MM/DD/YYYY
    filename1
    161179
    16789
    1875
    90783
    MM/DD/YYYY
    filename2
    xxxxxx
    xxxxx
    xxxx
    xxxxx
    MM/DD/YYYY
    filename3
    xxxxxx
    xxxxx
    xxxx
    xxxxx
    Is this possible? I can't imagine having to go through each and every file one by one. Please help!!!

    Hello
    You may try the following AppleScript script. It will ask you to choose a root folder where to start searching for *.map files and then create a CSV file named "out.csv" on desktop which you may import to Excel.
    set f to (choose folder with prompt "Choose the root folder to start searching")'s POSIX path
    if f ends with "/" then set f to f's text 1 thru -2
    do shell script "/usr/bin/perl -CSDA -w <<'EOF' - " & f's quoted form & " > ~/Desktop/out.csv
    use strict;
    use open IN => ':crlf';
    chdir $ARGV[0] or die qq($!);
    local $/ = qq(\\0);
    my @ff = map {chomp; $_} qx(find . -type f -iname '*.map' -print0);
    local $/ = qq(\\n);
    #     CSV spec
    #     - record separator is CRLF
    #     - field separator is comma
    #     - every field is quoted
    #     - text encoding is UTF-8
    local $\\ = qq(\\015\\012);    # CRLF
    local $, = qq(,);            # COMMA
    # print column header row
    my @dd = ('column 1', 'column 2', 'column 3', 'column 4', 'column 5', 'column 6');
    print map { s/\"/\"\"/og; qq(\").$_.qq(\"); } @dd;
    # print data row per each file
    while (@ff) {
        my $f = shift @ff;    # file path
        if ( ! open(IN, '<', $f) ) {
            warn qq(Failed to open $f: $!);
            next;
        $f =~ s%^.*/%%og;    # file name
        @dd = ('', $f, '', '', '', '');
        while (<IN>) {
            chomp;
            $dd[0] = \"$2/$1/$3\" if m%Link Time\\s+=\\s+([0-9]{2})/([0-9]{2})/([0-9]{4})%o;
            ($dd[2] = $1) =~ s/ //g if m/([0-9 ]+)\\s+bytes of CODE\\s/o;
            ($dd[3] = $1) =~ s/ //g if m/([0-9 ]+)\\s+bytes of DATA\\s/o;
            ($dd[4] = $1) =~ s/ //g if m/([0-9 ]+)\\s+bytes of XDATA\\s/o;
            ($dd[5] = $1) =~ s/ //g if m/([0-9 ]+)\\s+bytes of FARCODE\\s/o;
            last unless grep { /^$/ } @dd;
        close IN;
        print map { s/\"/\"\"/og; qq(\").$_.qq(\"); } @dd;
    EOF
    Hope this may help,
    H

  • Having trouble reading specific lines from a text file and displaying them in a listbox

    I am trying to read specific lines from all of the text files in a folder that are reports. When I run the application I get the information from the first text file and then it returns this error: "A first chance exception of type 'System.ArgumentOutOfRangeException'
    occurred in mscorlib.dll"
    Below is the code from that form. 
    Option Strict On
    Option Infer Off
    Option Explicit On
    Public Class frmInventoryReport
    Public Function ReadLine(ByVal lineNumber As Integer, ByVal lines As List(Of String)) As String
    Dim intTemp As Integer
    intTemp = lineNumber
    Return lines(lineNumber - 1)
    lineNumber = intTemp
    End Function
    Public Function FileMatches(ByVal folderPath As String, ByVal filePattern As String, ByVal phrase As String) As Boolean
    For Each fileName As String In IO.Directory.GetFiles(folderPath, filePattern)
    If fileName.ToLower().Contains(phrase.ToLower()) Then
    Return True
    End If
    Next
    Return False
    End Function
    Private Sub frmInventoryReport_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim intcase As Integer = 1
    Dim strTemp, strlist, strFile As String
    Dim blnCheck As Boolean = True
    strFile = "Report Q" & intcase.ToString & ".txt"
    Do While blnCheck = True
    strFile = "Report Q" & intcase.ToString & ".txt"
    Dim objReader As New System.IO.StreamReader("E:\Furry Friends Animal Shelter Solution\Furry Friends Animal Shelter\" & strFile)
    Dim allLines As List(Of String) = New List(Of String)
    Do While objReader.Peek <> -1
    allLines.Add(objReader.ReadLine())
    Loop
    objReader.Close()
    strlist = ReadLine(1, allLines) & "" & ReadLine(23, allLines)
    lstInventory.Items.Add(strlist)
    intcase += 1
    strTemp = intcase.ToString
    strFile = "Report Q" & intcase.ToString & ".txt"
    blnCheck = FileMatches("E:\Furry Friends Animal Shelter Solution\Furry Friends Animal Shelter\", "*.txt", intcase.ToString)
    Loop
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim intcase As Integer = 1
    Dim strTemp, strlist, strFile As String
    Dim blnCheck As Boolean = True
    strFile = "Report Q" & intcase.ToString & ".txt"
    Do While blnCheck = True
    strFile = "Report Q" & intcase.ToString & ".txt"
    Dim objReader As New System.IO.StreamReader("E:\Furry Friends Animal Shelter Solution\Furry Friends Animal Shelter\" & strFile)
    Dim allLines As List(Of String) = New List(Of String)
    Do While objReader.Peek <> -1
    allLines.Add(objReader.ReadLine())
    Loop
    objReader.Close()
    strlist = ReadLine(1, allLines) & "" & ReadLine(23, allLines)
    lstInventory.Items.Add(strlist)
    intcase += 1
    strTemp = intcase.ToString
    strFile = "Report Q" & intcase.ToString & ".txt"
    blnCheck = FileMatches("E:\Furry Friends Animal Shelter Solution\Furry Friends Animal Shelter\", "*.txt", intcase.ToString)
    Loop
    End Sub
    End Class
    Sorry I'm just beginning coding and I'm still a noob. Any help is appreciated. Thank you!

    Ok, so if I'm following this correctly you should be able to just loop through all of the files in that folder whose file name matches the pattern and then read the first 22 lines, recording only the first and the last.
    Exactly how you store the animal data probably depends on how you are going to display it and what else you are going to do with it.  Is there anything other than name and cage number that should be associated with each animal?
    You might want to make a dataset with a datatable to describe the animal, or you might write a class, or you might just use something generic like a Tuple.  Here's a simple class example:
    Public Class Animal
    Public Property Name As String
    Public Property Cage As String
    Public Overrides Function ToString() As String
    Return String.Format("{0} - {1}", Name, Cage)
    End Function
    End Class
    With that you can use a routine like the following to loop through all of the files and read each one:
    Dim animals As New List(Of Animal)
    Dim folderPath As String = "E:\Furry Friends Animal Shelter Solution\Furry Friends Animal Shelter\"
    For Each filePath As String In System.IO.Directory.GetFiles(folderPath, "Report Q?.txt")
    Using reader As New System.IO.StreamReader(filePath)
    Dim lineIndex As Integer = 0
    Dim currentAnimal As New Animal
    While Not reader.EndOfStream
    Dim line As String = reader.ReadLine
    If lineIndex = 0 Then
    currentAnimal.Name = line
    ElseIf lineIndex = 22 Then
    currentAnimal.Cage = line
    Exit While
    End If
    lineIndex += 1
    End While
    animals.Add(currentAnimal)
    End Using
    Next
    'do something to display the animals list
    Then you might bind the animals list to a ListBox, or loop through the list and populate a ListView.  If you decided to fill a datatable instead of making Animal instances, then you might bind the resulting table to a DataGridView.
    There are lots of options depending on what you want and what all you need to do.
    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

  • Program to read only specific words in each Line in a text file

    Hi
    I have a question
    I need to write a program where the program must read only specific words in each line
    I will give you an example...
    PSAPPSRV.21201      1-42 13.35.54 238.360 Cur#1.HDEV RC=0 Dur=0.000 COM Stmt=SELECT VERSION FROM PSVERSION WHERE OBJECTTYPENAME = 'SYS'
    PSAPPSRV.21201      1-43 13.35.54 0.040 Cur#2.HDEV RC=0 Dur=0.000 COM Stmt=SELECT STYLESHEETNAME FROM PSOPTIONS
    These are two lines in my text file...now I need to read only the SQL statements present that is both SELECT statements.. Can you please suggest a method.......

    My first reaction to the question is why would you want such thing, but may be I am unknown :)
    Assuming you have the text as string, I mean
    String str = "PSAPPSRV.21201 1-42 13.35.54 238.360 Cur#1.HDEV RC=0 Dur=0.000 COM Stmt=SELECT VERSION FROM PSVERSION WHERE OBJECTTYPENAME = \'SYS\'";you can obtain the sql statement using substring method like
    String result = str.substring(str.indexOf("SELECT")); Again I assume there is no word SELECT preceding and the word SELECT is all caps.

Maybe you are looking for