Skip to content

Instantly share code, notes, and snippets.

@CurtHagenlocher
Created April 7, 2015 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CurtHagenlocher/10eb34d0fc3a48480fea to your computer and use it in GitHub Desktop.
Save CurtHagenlocher/10eb34d0fc3a48480fea to your computer and use it in GitHub Desktop.
This sample uses a header consisting of dashes to identify where the column boundaries are and then splits the file by those boundaries.
let
Source = Table.FromColumns({Lines.FromBinary(Web.Contents("http://www.aer.ca/data/WELLS/SPUDTHU.TXT"),null,null,1252)}),
Header = List.First(List.Select(Source[Column1], each Text.StartsWith(_, "--"))),
Positions = Text.PositionOf(Header, " ", -1),
Length = Text.Length(Header),
Lengths = List.Generate(
() => 0,
(i) => i <= List.Count(Positions),
(i) => i + 1,
(i) =>
let
start = if i = 0 then -1 /* to capture trailing space */ else Positions{i-1},
end = if i = List.Count(Positions) then Length else Positions{i}
in
end - start),
Split = Table.SplitColumn(Source,"Column1",Splitter.SplitTextByLengths(Lengths))
in
Split
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment