# Reading a file with blank last line

**URL:** <https://discourse.julialang.org/t/reading-a-file-with-blank-last-line/41257>\
**Category:** General Usage\
**Created:** [June 12, 2020, 9:56am UTC](https://discourse.julialang.org/t/reading-a-file-with-blank-last-line/41257 "2020-06-12T09:56:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![binarygcd](https://avatars.discourse-cdn.com/v4/letter/b/ec9cab/32.png) [@binarygcd](https://discourse.julialang.org/u/binarygcd)\
**Post date:** [June 12, 2020, 9:56am UTC](https://discourse.julialang.org/t/reading-a-file-with-blank-last-line/41257/1 "2020-06-12T09:56:43Z")

</div>

I made a code for a problem that gets its inputs from a file. The inputs are integers and the last line is blank. Below are the ones I’ve tried.

```julia
for line in eachline()
    isempty(strip(line)) && break
    n = parse(Int, line)

```

```julia
for line in Iterators.takewhile(x -> !isempty(strip(x)), eachline())
    n = parse(Int, line)

```

Are there better alternatives? I like ‘takewhile’ but it’s noticeably slower than the first.

---

<div class="post-metadata">

**Author:** ![pixel27](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pixel27/32/8902_2.png) [@pixel27](https://discourse.julialang.org/u/pixel27)\
**Post date:** [June 12, 2020, 10:48pm UTC](https://discourse.julialang.org/t/reading-a-file-with-blank-last-line/41257/2 "2020-06-12T22:48:02Z")

</div>

I would probably do something like:

```julia
for line in Iterators.filter(x -> !isempty(x), eachline())
end

```

Unless an empty line in the middle of the file signifies the end of the data.
