Created
September 6, 2013 20:10
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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