Dear all,
I might be too naive doing a line by line file read and throw out duplicated columns and write it back to another file.
The first loop iteration runs well but then an error LoadError: MethodError: objects of type IOBuffer are not callable
occured.
Here is a hopefully MWE.
BTW, since I’m new in Julia, I’d appreciate very much any style and performance issue improvement suggestions, thanks!
function removeDuplicates(in::IO, out::IO)
for l in eachline(in)
splt = split(l, ";")
println(splt)
knownDuplicates = Vector{String}()
for el in splt[4:end]
println(el)
println(knownDuplicates)
if !isempty(knownDuplicates) && in(el, knownDuplicates)
el = ""
else
push!(knownDuplicates, el)
end
end
write(out, join(splt, ";"))
end
end
function removeDuplicates(inFile::String, outFile::String)
open(outFile, "w") do out
open(inFile, "r") do in
removeDuplicates(in, out)
end
end
end
fakeData = """
"5674012";"530489692";"batch_145322";"10/31/2019 15:00:13";1;2;1;2;2;3;4;2;
"5674012";"530489702";"batch_145323";"10/31/2019 15:00:32";1;2;1;2;2;3;4;2;"
"5674012";"530489728";"batch_145327";"10/31/2019 15:01:56";1;2;1;2;2;3;4;2;"
"""
io = (IOBuffer = (in = IOBuffer(fakeData), out = IOBuffer()),
filename = (in = "list.txt", out = "nodup_julia.txt"))
@time removeDuplicates(io.IOBuffer.in, io.IOBuffer.out)
output:
SubString{String}["\"5674012\"", "\"530489692\"", "\"batch_145322\"", "\"10/31/2019 15:00:13", "\""]
"10/31/2019 15:00:13
String[]
"
["\"10/31/2019 15:00:13"]
ERROR: LoadError: MethodError: objects of type IOBuffer are not callable
Stacktrace:
[1] removeDuplicates(in::IOBuffer, out::IOBuffer)
@ Main c:\Users\janka\Git\juliaVsCpp\removeDuplicatesInRow_Julia.jl:33
[2] top-level scope
@ .\timing.jl:210
in expression starting at c:\Users\janka\Git\juliaVsCpp\removeDuplicatesInRow_Julia.jl:63
julia>
Thank you very much!
edit: my julia version
julia> versioninfo()
Julia Version 1.6.1
Commit 6aaedecc44 (2021-04-23 05:59 UTC)
Platform Info:
OS: Windows (x86_64-w64-mingw32)
CPU: Intel(R) Core(TM) i5-6300U CPU @ 2.40GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-11.0.1 (ORCJIT, skylake)
Environment:
JULIA_EDITOR = code-insiders
JULIA_NUM_THREADS =