Problem parsing a txt file

Hello,

I am reading a txt file with this format:

06/22/2021 {somenthing}
06/22/2021 {somenthing}
06/22/2021 {somenthing so long that goes
to the other line}
06/22/2021 {somenthing}

To read this file i am using:

open("test.txt") do f

line = 0
# read till end of file
while ! eof(f)
# read a new / next line for every iteration
s = readline(f)
line + = 1
println( "$s" )
end
end

Well, what i need is to ensure that each new line starts with a date, not a string as it happens when the text is too long. How can i do that?

if you’re just counting the number of “entry” (defined by starting with a date) in that file, you can use a regular expressing to match the dates as r"^\d{2}/\d{2}/\d{4}":

julia> open("test.txt") do f
          line = 0
          while !eof(f)
              s = readline(f)
              if occursin(r"^\d{2}/\d{2}/\d{4}", s)
                  line += 1
                  println(s)
              end
           end
           println(line)
       end
06/22/2021 {somenthing}
06/22/2021 {somenthing}
06/22/2021 {somenthing so long that goes
06/22/2021 {somenthing}
4
1 Like

Thanks. IÄşl try as soon as i get home. I am not counting the number of entry. I need to parse this file and i need each line starting with a date otherwise my code fails.

this is fine, you just need to modify the code such that you treat nextline as the same line until you hit a line that starts with a date, just need to modify the loop a bit.

then you should fix the file if possible

its is possible, the problem is that i get like 20 files like this per week…