# Is it possible to reset a new-line character when read txt file in julia?

**URL:** <https://discourse.julialang.org/t/is-it-possible-to-reset-a-new-line-character-when-read-txt-file-in-julia/19344>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [January 7, 2019, 6:17am UTC](https://discourse.julialang.org/t/is-it-possible-to-reset-a-new-line-character-when-read-txt-file-in-julia/19344 "2019-01-07T06:17:21Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![orange\_si](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/orange_si/32/6526_2.png) [@orange\_si](https://discourse.julialang.org/u/orange_si)\
**Post date:** [January 7, 2019, 6:17am UTC](https://discourse.julialang.org/t/is-it-possible-to-reset-a-new-line-character-when-read-txt-file-in-julia/19344/1 "2019-01-07T06:17:21Z")

</div>

In perl, if you want reset new-line character, you can use  
`$/="new_character"`. So is it possible to reset a new-line character when read txt file in julia ?

Thanks~  
Regard  
Si

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [January 7, 2019, 8:55am UTC](https://discourse.julialang.org/t/is-it-possible-to-reset-a-new-line-character-when-read-txt-file-in-julia/19344/2 "2019-01-07T08:55:09Z")

</div>

> [@orange\_si](#):
>
> reset new-line character

I don’t understand what this means.

If you want to remove trailing newlines from a string, use `chomp`.

---

<div class="post-metadata">

**Author:** ![ffevotte](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffevotte/32/6587_2.png) [@ffevotte](https://discourse.julialang.org/u/ffevotte)\
**Post date:** [January 7, 2019, 9:09am UTC](https://discourse.julialang.org/t/is-it-possible-to-reset-a-new-line-character-when-read-txt-file-in-julia/19344/3 "2019-01-07T09:09:18Z")

</div>

I don’t think that you can set a custom separator in a global way like you do in Perl. However, what you can do is read your file using `readuntil` instead of `readline` if you want to be able to specify a delimiter for the chunk that you want to read.

Here is an example taken from the documentation of `readuntil`, where the character `L` is used as a delimiter.

```julia
  julia> open("my_file.txt", "w") do io
             write(io, "JuliaLang is a GitHub organization.\nIt has many members.\n");
         end
  57
  
  julia> readuntil("my_file.txt", 'L')
  "Julia"

```

---

<div class="post-metadata">

**Author:** ![orange\_si](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/orange_si/32/6526_2.png) [@orange\_si](https://discourse.julialang.org/u/orange_si)\
**Post date:** [January 7, 2019, 9:46am UTC](https://discourse.julialang.org/t/is-it-possible-to-reset-a-new-line-character-when-read-txt-file-in-julia/19344/4 "2019-01-07T09:46:05Z")

</div>

> [@ffevotte](#):
>
> delimiter

sorry, I should use more accurate word like delimiter as @ffevotte

---

<div class="post-metadata">

**Author:** ![orange\_si](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/orange_si/32/6526_2.png) [@orange\_si](https://discourse.julialang.org/u/orange_si)\
**Post date:** [January 7, 2019, 10:01am UTC](https://discourse.julialang.org/t/is-it-possible-to-reset-a-new-line-character-when-read-txt-file-in-julia/19344/5 "2019-01-07T10:01:49Z")

</div>

thanks~ I should use delimiter. because don’t know the how many lines by new delimiter, so how to loop the all lines by new delimiter?

---

<div class="post-metadata">

**Author:** ![orange\_si](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/orange_si/32/6526_2.png) [@orange\_si](https://discourse.julialang.org/u/orange_si)\
**Post date:** [January 7, 2019, 10:10am UTC](https://discourse.julialang.org/t/is-it-possible-to-reset-a-new-line-character-when-read-txt-file-in-julia/19344/6 "2019-01-07T10:10:06Z")

</div>

I use this to loop

```julia
open("tmp") do file
	while ! eof(file)
		line = readuntil(file, ">")
		line = chomp(line)
		println("line is ",line)
	end
end

```

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [January 7, 2019, 10:27am UTC](https://discourse.julialang.org/t/is-it-possible-to-reset-a-new-line-character-when-read-txt-file-in-julia/19344/7 "2019-01-07T10:27:09Z")

</div>

Something like that, I don’t think you need `chomp` unless there is a newline to remove. Also, I would specify `readuntil(...; keep = false)` to be explicit, although that is the default.
