Skip to content

Instantly share code, notes, and snippets.

@deneuxj
Forked from OnorioCatenacci/FilterTextFile.fsx
Created October 24, 2011 16:18
Show Gist options
  • Save deneuxj/1309420 to your computer and use it in GitHub Desktop.
Save deneuxj/1309420 to your computer and use it in GitHub Desktop.
A quick and dirty F# Shell Script to filter a text file for all lines which match a certain string
(*
* Filter a specified file into a second file
* Onorio Catenacci
* 21 October 2011
*)
#r "System.dll"
open System.IO
//Remember:
//When running from the command line, the first argument that isn't the script name is 1
//When running from FSI window, the first argument that isn't the script name is 0
let main = function
[| _ ; source_file ; target_file |] ->
let t_strings =
File.ReadLines(source_file)
|> let pred prefix (cl : string) = cl.StartsWith(prefix) in Seq.filter (pred "Unit Disposition")
File.WriteAllLines(target_file,t_strings)
0
| _ ->
eprintfn "Bad arguments"
1
main fsi.CommandLineArgs;;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment