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 =
|> Seq.filter(fun x -> if x.Contains(“error”) then false else true)

let LookForWarning =
|> 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)


Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s