none
Unable to parse a CSV file using ; as a field delimitator RRS feed

  • Domanda

  • Hi,

             

    I have a log file: below a single line of the log:

    2012-10-10 ; 09:56:28 ; W3SVC ; OnPreprocHeaders ; 192.168.1.10 ;  ;  ; site.test.acme.com ; Mozilla/5.0 (X11; Linux x86_64; rv:11.0) Gecko/20100101 Firefox/11.0 ; GET ; /internet/default/acmecomunication/p/Arch/Arch/index.html ;

    I would like to parse the line using ; as a separator:

                                   

    2012-10-10         field #1
             09:56:28           field  #2
             W3SVC              field  #3
             OnPreprocHeaders   field  #4
             192.168.1.10       field  #5
             blank                   field  #6
             blank                   field  #7
             blank                    field  #8
             site.test.acme.com  field  #9
             Mozilla/5.0          field  #10
             (X11; Linux x86_64; rv:11.0) field  #11
             Gecko/20100101 Firefox/11.0   field  #12
             GET                 field  #13
             /internet/default/acmecomunica/p/Arch/Arch/index.html    field  #14

    I have tried this: 

    (\d+\-\d+\-\d+) ; (\d+\:\d+\:\d+.) ; (\S+) ; (\S+) ; (\d+\.\d+\.\d+\.\d+) ;  ;  ; (\S+) ; (\S+)\/(\d+)\.(\d+) (\(.*?\)) (.*\;)

    but dosen't work well.

    Below the result:

    1: (2012-10-10)
    2: (09:56:28)
    3: (W3SVC)
    4: (OnPreprocHeaders)
    5: (192.168.1.10)
    6: (site.test.acme.com)
    7: (Mozilla)
    8: (5)
    9: (0)
    10: ((X11; Linux x86_64; rv:11.0))
    11: (Gecko/20100101 Firefox/11.0 ; GET ; /internet/default/acmecomunica/p/Arch/Arch/index.html ;)

    Any suggestion?

    Thank you

    venerdì 23 novembre 2012 16:51

Risposte

  • Hi,

             

    I have a log file: below a single line of the log:

    2012-10-10 ; 09:56:28 ; W3SVC ; OnPreprocHeaders ; 192.168.1.10 ;  ;  ; site.test.acme.com ; Mozilla/5.0 (X11; Linux x86_64; rv:11.0) Gecko/20100101 Firefox/11.0 ; GET ; /internet/default/acmecomunication/p/Arch/Arch/index.html ;

    I would like to parse the line using ; as a separator:

                                   

    2012-10-10         field #1
             09:56:28           field  #2
             W3SVC              field  #3
             OnPreprocHeaders   field  #4
             192.168.1.10       field  #5
             blank                   field  #6
             blank                   field  #7
             blank                    field  #8
             site.test.acme.com  field  #9
             Mozilla/5.0          field  #10
             (X11; Linux x86_64; rv:11.0) field  #11
             Gecko/20100101 Firefox/11.0   field  #12
             GET                 field  #13
             /internet/default/acmecomunica/p/Arch/Arch/index.html    field  #14

    I have tried this: 

    (\d+\-\d+\-\d+) ; (\d+\:\d+\:\d+.) ; (\S+) ; (\S+) ; (\d+\.\d+\.\d+\.\d+) ;  ;  ; (\S+) ; (\S+)\/(\d+)\.(\d+) (\(.*?\)) (.*\;)

    but dosen't work well.

    Below the result:

    1: (2012-10-10)
    2: (09:56:28)
    3: (W3SVC)
    4: (OnPreprocHeaders)
    5: (192.168.1.10)
    6: (site.test.acme.com)
    7: (Mozilla)
    8: (5)
    9: (0)
    10: ((X11; Linux x86_64; rv:11.0))
    11: (Gecko/20100101 Firefox/11.0 ; GET ; /internet/default/acmecomunica/p/Arch/Arch/index.html ;)

    Any suggestion?

    Thank you

    Hi,

    here an example:

    string pattern = "2012-10-10 ; 09:56:28 ; W3SVC ; OnPreprocHeaders ; 192.168.1.10 ;  ;  ; site.test.acme.com ; Mozilla/5.0 (X11; Linux x86_64; rv:11.0) Gecko/20100101 Firefox/11.0 ; GET ; /internet/default/acmecomunication/p/Arch/Arch/index.html;";
    var result = Regex.Split(pattern, ";");
    foreach (var item in result)
    {
      Console.WriteLine(item);                
    }

    Maurizio



    Maurizio Cinti: [MCT, MCPD]
    Blog: http://mauriziocinti.com
    Twitter: @mcinti78
    LinkedIn: it.linkedin.com/in/mauriziocinti

    • Proposto come risposta Maurizio Cinti mercoledì 12 dicembre 2012 23:38
    • Contrassegnato come risposta Irina Turcu mercoledì 25 settembre 2013 13:47
    venerdì 23 novembre 2012 20:37