如何从日志文件中提取数据? [英] How can I extract data from a log file?

查看:183
本文介绍了如何从日志文件中提取数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

评论je peux axtraire desdonnéesd'un fichier log et les stokcker ailleurs


comment je peux axtraire des données d''un fichier log et les stokcker ailleurs


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]添加了代码块,将其翻译成主题(通过Google),然后移入了正文-OriginalGriff [/edit]




[edit]Code block added, subject translated (via Google) and moved into body - OriginalGriff[/edit]

推荐答案

此MSDN文章:

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

给出了一个很好的简单示例,将字符串数据写出到文件中.

如果您需要在Excel中打开此文件,最简单的方法是通过在字符串之间放置逗号和换行符(Environment.NewLine)来编写一个* .CSV(逗号分隔值)文件,以将它们排列成行和列

例如

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

我建议使用stringBuilder类在将此文本写入文件之前对其进行构建.
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.


您可以尝试 www .cppfrance.com .


dans ce petit bout de code to ce que j'ai reussi a faire c'est de mettre les regex(le regles)倒入初学者演讲,并确定自己的身份. ce que j''essaye de faire维护者c" est de stocker lesdonnées包括entre c" est deux valeurs dans un autres fichier pour les使者使fichier excel发挥作用

在这小段代码中,我所要做的就是将regex(《规则》)从某些新方法开始播放,这是另一个价值.我现在想做的是将数据存储在两个值之间是另一个要发送到excel的文件
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


这篇关于如何从日志文件中提取数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆