# Removing the first line in a text file

**URL:** <https://discourse.julialang.org/t/removing-the-first-line-in-a-text-file/35521>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [March 4, 2020, 2:39pm UTC](https://discourse.julialang.org/t/removing-the-first-line-in-a-text-file/35521 "2020-03-04T14:39:59Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [March 4, 2020, 6:05pm UTC](https://discourse.julialang.org/t/removing-the-first-line-in-a-text-file/35521/6 "2020-03-04T18:05:41Z")

</div>

Even simpler:

```julia
open("file_to_read") do input
    open("test.txt", "w") do output
        for line in Iterators.drop(eachline(input), 1)
            println(output, line)
        end
    end
end

```

If you want to maximize speed, and avoid the extraneous newline pointed out by @yuyichao, it would be faster to read everything after the newline in a block:

```julia
open("file_to_read") do input
    readuntil(input, '\n')
    write("file_to_write", read(input))
end

```

This implementation is even shorter than the code based on `eachline`. (And it will be vastly faster than spawning a Unix program like `tail`, not to mention being more portable.)

The only downside of this approach is that it might take a lot of memory if you have an enormous file. A more general implementation would probably read the data in large blocks, similar [to this code](https://discourse.julialang.org/t/how-to-obtain-the-result-of-a-diff-between-2-files-in-a-loop/23784/4).

---

_[View the full topic](https://discourse.julialang.org/t/removing-the-first-line-in-a-text-file/35521)._
