Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7988041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:19:16+00:00 2026-06-04T12:19:16+00:00

I want to parse file and delete some header strings on ruby. File(s) to

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T12:19:18+00:00Added an answer on June 4, 2026 at 12:19 pm

    It’s a trivial task (assuming the file is well-formed).

    Something like this:

    lines = # read lines from file
    
    is_header_mode = false
    lines.each do |line|
       if line == '---'
         is_header_mode = !is_header_mode
       else
         puts line unless is_header_mode
       end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to be able to parse file paths like this one: /var/www/index.(htm|html|php|shtml) into
I am using opencsv to parse text file and generate List<String[]> now I want
I have text file with several thousands lines. I want to parse this file
i want parse xml file, which does't have xml extension, like this: http://bizonek.wrzuta.pl/xml/plik/1ANdXCgTOit/unknow/undefined/643/ my
I want to parse the html file, pdf file, csv file and text file.Now
I want to pull something from the server (no delete), parse the file in
I want to parse a file and delete all leading 0's of a number
I want to parse the text line from the Wavefront OBJ file . Currently
I have a simple but huge xml file like below. I want to parse
I want to parse an XML file using SAX parser in java with this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.