I want to parse file and delete some header strings on ruby.
File(s) to be parsed looks like this.
---
some
text
text2
string
and
so
on
---
another string
and the other
And I want to remove
---
some
text
text2
string
and
so
on
---
this part.
Edit: I wrote a ruby code like this
file = File.open("test")
a = file.readlines
skip = 0
a.each do |line|
if line.match("---\n")
if skip == 1
skip-=1
else
skip+=1
end
else
if skip != 1
print line
end
end
end
This works, however, I think my code is dirty and should be cleaned.
How can I simplify my code?
It’s a trivial task (assuming the file is well-formed).
Something like this: