Click here to Skip to main content
15,884,353 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
What i am trying to do is to parse below text from a text file.
10:06:59:Sell Order 59266 5,000 TL at 22.20 Queued in the Regular Book Regular Market  for Account # CC1233
10:06:59: Ticket 47930 Sold Order 59165266 5,000 TGL Regular Market filled at 22.20  - remaining 0 For Account # CC1233
10:31:57:Buy Order 59172 1,000 GHI at 21.90 Queued in the Regular Book Regular Market  for Account # CC1233
10:32:11:Buy Order 59127 2,000 PIC at 25.31 Queued in the Regular Book Regular Market  for Account # CC1233
10:32:47: Ticket 47922 Bought Order 59173072 1,000 GHNI Regular Market filled at 21.90  - remaining 0 For Account # CC1233
10:35:29:Buy Order 59135 1,000 NYP at 38.25 Queued in the Regular Book Regular Market  for Account # CC1233
10:59:17:Buy Order 59056 2,000 MYF at 18.35 Queued in the Regular Book Regular Market  for Account # CC1233
10:59:17: Ticket 47959 Bought Order 59180956 2,000 MLCF Regular Market filled at 18.35  - remaining 0 For Account # CC1322
10:59:36: Buy Order 59127  2,000 PYC at 25.35 Changed in the Regular Book Regular Market  for Account # CC1233
11:04:49:Buy Order 59707 5,000 BYL at 14.70 Queued in the Regular Book Regular Market  for Account # CC1233
11:08:18: Buy Order 59635  1,000 NYP at 38.50 Changed in the Regular Book Regular Market  for Account # CC1233
11:08:18:Buy Order 54035 1,000 NYP at 38.50 Queued in the Regular Book Regular Market  for Account # CC1233
11:08:18: Ticket 47318 Bought Order 59174035 500 NYP Regular Market filled at 38.50  - remaining 500 For Account # CC1233
11:08:18: Ticket 47959 Bought Order 59174035 500 NYP Regular Market filled at 38.50  - remaining 0 For Account # CC1233

This file is continuously updated automatically via another software. I want to parse on those line with a word "Ticket" in it there are some other lines with other text.

Separate the selected line (the one with ticket word) using space and saving them in database. keeping in mind the file is updated continuously.

is it even possible..?
Posted
Updated 6-May-13 22:00pm
v2
Comments
Prasad Khandekar 7-May-13 4:04am    
As long as the other software is appending at the end and you are oepning the file in read mode it should be possible. You will have to keep remembering the index of the last row read or better the byte offset by your code though. The trick or rather challenging part will be to correctly identify the partial lines.

Regards,
Mehdi Gholam 7-May-13 4:05am    
Looks simple enough, what have you done so far?
Nouman |slam 7-May-13 4:13am    
@Mehdi: I am a new programmer and don't know much. so i haven't done anything.

@Parsad: how can i remember the index of last row as i am reading my particular keyword in a particular line. it might be possible that the last line of the file does not contain the desire keyword.

o may be i am just lost.
Madhav Hatwalne 7-May-13 4:27am    
where you are storing this data?
Nouman |slam 7-May-13 4:33am    
in array.

Of course it is possible.
At each (periodic) 'parse and insert operation' you have to:
  1. Check if current file size is bigger than a certain amount with respect 'last operation' file size (abort operation if it is smaller or equal).
  2. Parse only the augmented part of the input file, inserting in the database all the lines containing the word 'Ticket' (have a look at String.Contains[^] method).
  3. Update 'last operation' file size with current one.
     
    Share this answer
     
    C#
    U have to read file and insert it into one datatable
    
                int counter = 0;
                string line;
    
                DataTable table = new DataTable();
                DataColumn cl = new DataColumn("Text");
                table.Columns.Add(cl);
                // Read the file and display it line by line.
                System.IO.StreamReader file =
                   new System.IO.StreamReader("Filepath/test.txt");
                while ((line = file.ReadLine()) != null)
                {
    
                    DataRow dr = table.NewRow();
                    Console.WriteLine(line);
                    dr["Text"] = line;
                    table.Rows.Add(dr);
                    counter++;
                }
    
                file.Close();
    
    
    
                // Suspend the screen.
                Console.ReadLine();
    
    After inserting data into datatable apply table sorting using select
    
    u can refer this example
    
    DataTable table = new DataTable("Players");
    	table.Columns.Add(new DataColumn("Size", typeof(int)));
    	table.Columns.Add(new DataColumn("Sex", typeof(char)));
    
    	table.Rows.Add(100, 'f');
    	table.Rows.Add(235, 'f');
    	table.Rows.Add(250, 'm');
    	table.Rows.Add(310, 'm');
    	table.Rows.Add(150, 'm');
    
    	// Search for people above a certain size.
    	// ... Require certain sex.
    	DataRow[] result = table.Select("Size >= 230 AND Sex = 'm'");
    	foreach (DataRow row in result)
    	{
    	    Console.WriteLine("{0}, {1}", row[0], row[1]); // Here you can insert those rows in Array
    	}
     
    Share this answer
     
    v3
    Comments
    Madhav Hatwalne 7-May-13 5:46am    
    is your objective accomplished?
    Nouman |slam 7-May-13 6:16am    
    i am still working on it.. will update soon..

    This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



    CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900