Skip to content

Instantly share code, notes, and snippets.

@kmoormann
Created September 6, 2013 20:10
Show Gist options
  • Save kmoormann/6469261 to your computer and use it in GitHub Desktop.
Save kmoormann/6469261 to your computer and use it in GitHub Desktop.
An F# script that will remove the string "NULL" from a text delimited file. Often when saving a SQL query result to a file NULL values will be saved as the string "NULL". This removes them so that they are easier to process
open System.IO
let lines path =
System.IO.File.ReadAllLines(path)
let writeFile lines path =
System.IO.File.Delete(path)
System.IO.File.AppendAllLines(path, lines)
let replaceNulls path =
let origFileNameAndExtension = System.IO.Path.GetFileName(path)
let extension = System.IO.Path.GetExtension(path)
let name = System.IO.Path.GetFileNameWithoutExtension(path)
let NewFileNameAndExtension = origFileNameAndExtension.Replace(name,name + "noNulls")
let fileLines = lines path
let RemoveNullLines = fileLines |> Array.map(fun x -> x.Replace("NULL",""))
writeFile RemoveNullLines (path.Replace(origFileNameAndExtension, NewFileNameAndExtension))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment