Reading CSV and FWF files
Reading comma-separated value (CSV) and fixed-width files (FWF) are commonly needed operations in data processing. In this recipe, we look at how Julia supports these operations.
Getting ready
Start the Julia command line and create two IOBuffer
objects from which we'll read data:
julia> csv = """a,b,c 11,2,3 4,555,6 7,8,9999""" "a,b,c\n11,2,3\n4,555,6\n7,8,9999" julia> iocsv = IOBuffer(csv) IOBuffer(data=UInt8[...], readable=true, writable=false, seekable=true, append=false, size=29, maxsize=Inf, ptr=1, mark=-1) julia> fwf = """a b c 11 2 3 4 555 66 7 8 9999""" "a b c\n11 2 3\n4 555 66\n7 8 9999" julia> iofwf = IOBuffer(fwf) IOBuffer(data=UInt8[...], readable=true, writable=false, seekable=true, append=false, size=47, maxsize=Inf, ptr=1, mark=-1)
Note
In the GitHub repository for this recipe, you will find the commands.txt
file, which...