Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
comment je peux axtraire des données d'un fichier log et les stokcker ailleurs


C#
using System;
using System.IO;
using System.Text.RegularExpressions;

class Program
{

    public struct command
    {  
        public int com, side, clientAppliId, quantity, price, validity;
        public int modality, clientCodeType, subNegociationCode, subClassOrder;
        public int origTime, tradingPhase, postingMode, clearingMode, TON, restriction, settlementType;
        public int applicationFlag, mnemo, GLID, typeMessage, classOrder, noUti;
        public string currency, confirmation;
    }

    static void Main()
    {
        Regex g = new Regex(@"(?<h>\d+):(?<min>\d+):(?<sec>\d+):(?<ms>\d+)+ GLDataCmd");
        Regex g2=new Regex(@"SCRecord");
        Regex g2_fin = new Regex(@"}");

        using (StreamReader r = new StreamReader("C:\\Program Files\\GLTrade\\slev5\\log\\P10_P3_recv_20110817.log"))
        {
            string line;

            while ((line = r.ReadLine()) != null)
            {
              Match m=g.Match(line);
              
                if ( m.Success)
                {
                    Console.WriteLine(line);
                  
                    while ((line = r.ReadLine()) != null)
                    {
                        Match c = g2.Match(line);
                        if (c.Success)
                        { 
                            Console.WriteLine(line);
                            while ((line = r.ReadLine()) != null)
                            {
                                Match k = g2_fin.Match(line);
                                if (!k.Success)
                                { 
                                    Console.WriteLine(line);

                                }
                                else { break; }
                            }
                           break;
                        }
                    }
                    //string v = m.Groups[1].Value;
                    //string w = m.Groups[2].Value;
                }
            }
            Console.ReadLine();
        }
    }
}



[edit]Code block added, subject translated (via Google) and moved into body - OriginalGriff[/edit]
Posted
Updated 6-Sep-11 3:57am
v2
Comments
#realJSOP 6-Sep-11 9:54am    
English only
Paul E Davies 6-Sep-11 9:56am    
What's the problem you are experiencing with the code?
ammou004 6-Sep-11 10:32am    
i want to extract data from the texte file i just wrote the regex of the begining end the end of the reading

This MSDN article:

http://msdn.microsoft.com/en-us/library/6ka1wd3w.aspx

Gives a nice simple example of writing string data out to a file.

If you require this file to be opened in Excel the simplest way to do so is to write a *.CSV (comma separated value) file by placing commas and line breaks (Environment.NewLine)between your strings to arrange them into rows and columns

e.g.

R1C1,R1C2,R1C3[Environment.NewLine]
R2C1,R2C2,R2C3[Environment.NewLine]
R3C1,R3C2,R3C3[Environment.NewLine]

i recommend using the stringBuilder class to build up this text prior to writing it to the file.
 
Share this answer
 
You might try www.cppfrance.com also.
 
Share this answer
 
dans ce petit bout de code tout ce que j'ai reussi a faire c'est de mettre les regex( le regles ) pour commencer la lecture a partir d'une certaine vleure jussqu'a une autre valeur . ce que j'essaye de faire maintenant c'est de stocker les données comprises entre c'est deux valeurs dans un autres fichier pour les envoyer ensuite a fichier excel

in this small piece of code all I managed to do is put the regex (the Regulations) to start playback from some vleure jussqu'a another value. what I'm trying to do now is to store the data between two values ​​is another file to send then to excel
 
Share this answer
 
v2
Comments
OriginalGriff 6-Sep-11 9:59am    
I'm sure English is not your native language, but it is the default language for this site.
Please, either try to find a translation of your question to English, or find a site in your own native language, as they may be able to help you better than we can!
ammou004 6-Sep-11 10:07am    
ah ok i wrote in frensh but the translaition was wrong . sorry !
in this small piece of code all I managed to do is put the regex (the Regulations) to start playback from some value to another value. what I'm trying to do now is to store the data between the two values ​​in another file to send then to excel an excel file
i hope you're understanding me

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