linux - Extracting specific fields from a log file and export it to csv file using C# -


this code have written in c# shows contains in sample.log file 110mb in size.

using system; using system.io; using system.text;      class program     {         static void main(string[] args)         {              filestream fs = new filestream("sample.log", filemode.open, fileaccess.read);             streamreader sr = new streamreader(fs);             string strfromfile;             stringbuilder resultstr = new stringbuilder();             while ((strfromfile = sr.readline()) != null)           {              // separator char seems char 1             string[] splitstrs = strfromfile.split(new char[] {(char)1});                     (int = 0; < splitstrs.length; i++)             {                    if (splitstrs[i].startswith("52="))                 {                     resultstr.append(splitstrs[i] + " ");                 }                 else if (splitstrs[i].startswith("55="))                 {                     resultstr.append(splitstrs[i] + " ");                 }                 else if (splitstrs[i].startswith("132="))                 {                     resultstr.append(splitstrs[i] + " ");                 }                 else if (splitstrs[i].startswith("133="))                 {                     resultstr.append(splitstrs[i] + " ");                 }                 else if (splitstrs[i].startswith("35="))                 {                     resultstr.append(splitstrs[i] + " ");                 }                }              console.writeline(resultstr);             resultstr.length = 0;          }             sr.close();             fs.close();             console.readkey();         }     } 

i getting output,

output:

35=5 52=20101219-18:05:01.522  35=a 52=20101219-18:06:01.504  35=a 52=20101219-18:06:02  35=1 52=20101219-18:06:02  35=r 52=20101219-18:06:01.847 55=eur/usd  

now problem how write output in csv file? idea.

rather write own: log parser 2.2:

log parser powerful, versatile tool provides universal query access text-based data such log files, xml files , csv files, key data sources on windows® operating system such event log, registry, file system, , active directory®. tell log parser information need , how want processed. results of query can custom-formatted in text based output, or can persisted more specialty targets sql, syslog, or chart.

log parser's built-in input formats can retrieve data following sources:

  • iis log files (w3c, iis, ncsa, centralized binary logs, http error logs, urlscan logs, odbc logs)
  • windows event log
  • generic xml, csv, tsv , w3c - formatted text files (e.g. exchange tracking log files, personal firewall log files, windows media® services log files, ftp log files, smtp log files, etc.)
  • windows registry
  • active directory objects
  • file , directory information
  • netmon .cap capture files
  • extended/combined ncsa log files

for linux use awstats:

awstats can analyze lot of log formats: apache ncsa combined log files (xlf/elf) or common (clf), iis log files (w3c), webstar native log files , other web, proxy, wap or streaming servers log files (but ftp or mail log files).

awstats logfile analyzer 7.0 documentation: faq

also: logparser (microsoft's one) or similar unix?


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -