# Streaming replace of file content before reading into lines

**URL:** <https://discourse.julialang.org/t/streaming-replace-of-file-content-before-reading-into-lines/56666>\
**Category:** General Usage\
**Created:** [March 7, 2021, 9:04am UTC](https://discourse.julialang.org/t/streaming-replace-of-file-content-before-reading-into-lines/56666 "2021-03-07T09:04:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![JuergenD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juergend/32/18970_2.png) [@JuergenD](https://discourse.julialang.org/u/JuergenD)\
**Post date:** [March 7, 2021, 9:04am UTC](https://discourse.julialang.org/t/streaming-replace-of-file-content-before-reading-into-lines/56666/1 "2021-03-07T09:04:46Z")

</div>

Sorry, it seems to be a simple question, but I’m not able to figure out how to do it in Julia. We receive text files, but they have ‘\01’ or ‘\00’ as newline. We’d like read (stream) the file content, map ‘\01’ to ‘\r’ and then continue reading the lines. Something like (pseudo code):

```julia
    open("myfile.dat", read=true) do fd
        # fd = map(fd, '\01' => '\r') # <= How to do this?
        fd = replace(fd, '\01' => '\r') # More appropriate, as pointed our by nilshg
        for line in eachline(fd)
            ...
        end
    end

```

Preferably it should work with input from files, cmds and IOBuffer

I know we could invoke an external command to do the translation, but we are using Windows as well as Linux, and we’d like an approach that easily works on both.

Thanks a lot for your help

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [March 7, 2021, 10:51am UTC](https://discourse.julialang.org/t/streaming-replace-of-file-content-before-reading-into-lines/56666/2 "2021-03-07T10:51:33Z")

</div>

I’m not sure I understand what you mean by `map` - your pseudocode looks as if you might be looking for `replace`?

---

<div class="post-metadata">

**Author:** ![JuergenD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juergend/32/18970_2.png) [@JuergenD](https://discourse.julialang.org/u/JuergenD)\
**Post date:** [March 7, 2021, 11:32am UTC](https://discourse.julialang.org/t/streaming-replace-of-file-content-before-reading-into-lines/56666/3 "2021-03-07T11:32:07Z")

</div>

good point, `replace` is more appropriate.

May be also not explicit enough in text: we want to stream the data, as the files are large. Reading all of the file content into memory, replace, and then split into lines, is not what we are looking for.

---

<div class="post-metadata">

**Author:** ![JuergenD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juergend/32/18970_2.png) [@JuergenD](https://discourse.julialang.org/u/JuergenD)\
**Post date:** [March 15, 2021, 11:41am UTC](https://discourse.julialang.org/t/streaming-replace-of-file-content-before-reading-into-lines/56666/4 "2021-03-15T11:41:12Z")

</div>

Is anybody able to help me with this?
