Read and Parse file in F#

Sample code 

open System.IO
open System

let ParseFile =
let fileData = File.ReadAllLines(@”C:\temp\log.log”)

let LookForErrors =
fileData
|> Seq.filter(fun x -> if x.Contains(“error”) then false else true)

let LookForWarning =
fileData
|> Seq.filter(fun x -> if x.Contains(“warning”) then true else false)

let mynewfiledata =
let mynewfiledata = Seq.append LookForWarning LookForErrors
let FileSummary = “Number of Entries : ” + fileData.Length.ToString() + ” Number of Errors : ” + (LookForErrors |> Seq.length).ToString()
Seq.append ( FileSummary |> Seq.singleton) mynewfiledata

File.WriteAllLines(“c:\\temp\Test.txt”, mynewfiledata)

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s