Google Groups

Re: Extracting lines from a file


LRP May 4, 2011 2:49 PM
Posted in group: erlangcamp
Thanks, Garrett!

LRP

-----Original Message-----
From: "Garrett Smith" <g...@rre.tt>
Sent: Wednesday, May 4, 2011 4:24pm
To: erlan...@googlegroups.com
Subject: Re: Extracting lines from a file

If your files aren't larger than available memory:

{ok, Bin} = file:read_file(File),
re:run(Bin, "\n*^(.*)$\n*^(.*)$", [multiline, {capture, all_but_first, list}])

On Wed, May 4, 2011 at 3:15 PM,  <ll...@writersglen.com> wrote:
> Hello,
>
> I need to extract the first two non-blank lines from a file; e.g. discard all blank ("\n") lines before the first and between the first and second line.
>
> My solutions get rather kludgy. Can anyone suggest an elegant way to do this?
>
> Thanks,
>
> LRP
>
>
>
>
>
>