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

  • SEARCH
  • Home
  • 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 7911549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:17:18+00:00 2026-06-03T13:17:18+00:00

I have a kind of csv file, with some extra parameters. I don’t want

  • 0

I have a kind of csv file, with some extra parameters. I don’t want to write my own parser since I know there are alot of good ones out there. The problem is that I’m unsurtan if there is any parser that could handle my scenario.
My csv file looks like this:

The CSV file

I would like to first read the second lines below # ADM so in this case 3 lines. And the I would like to read the second line after # Prov.

Is there any good parser or reader that I could use that would help me with this, and how would I write to handle my scenario?

The extension of my file is not .csv either, it’s .lab , but I guess thats not going to be a problem ?

  • 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-03T13:17:21+00:00Added an answer on June 3, 2026 at 1:17 pm

    Fore, I didn’t see a spefic language for the task, and read too late about c#. Here is a perl solution, but is well commented, so I hope it can be useful and easy to translate to other languages.

    Assuming a test file (infile) like:

    1
    2
    3
    4
    5
    
    #Adm
    6                                                                                                                                                                                                                                            
    7                                                                                                                                                                                                                                            
    
    #Prov                                                                                                                                                                                                                                        
    8                                                                                                                                                                                                                                            
    9                                                                                                                                                                                                                                            
    
    #Adm                                                                                                                                                                                                                                         
    10                                                                                                                                                                                                                                           
    11                                                                                                                                                                                                                                           
    
    #Prov                                                                                                                                                                                                                                        
    12                                                                                                                                                                                                                                           
    13                                                                                                                                                                                                                                           
    
    #Adm                                                                                                                                                                                                                                         
    14                                                                                                                                                                                                                                           
    15                                                                                                                                                                                                                                           
    
    #Prov                                                                                                                                                                                                                                        
    16                                                                                                                                                                                                                                           
    17
    

    Content of script.pl:

    use warnings;
    use strict;
    
    ## Assign empty value to read file by paragraphs.
    $/ = qq[];
    
    ## Arrays to save second row of its section.
    my (@adm, @prov);
    
    ## Regex to match beginning of section.
    my $regex = qr/(?:#(?|(Adm)|(Prov)))/;
    
    ## Read file.
    while ( <> ) { 
    
        ## Remove last '\n'.
        chomp;
    
        ## If matches the section and it has at least two lines...
        if ( m/\A${regex}/ and tr/\n/\n/ == 2 ) { 
    
            ## Group the section name ($1) and its second line ($2).
            if ( m/\A${regex}.*\n^(.*)\Z/ms ) { 
    
                ## Save line in an array depending of section's value.
                if ( $1 eq q[Adm] ) { 
                    push @adm, $2; 
                }   
                elsif ( $1 eq q[Prov] ) { 
                    push @prov, $2; 
                }   
            }   
        }   
    }
    
    ## Print first lines of 'Adm' section and later lines of 'Prov' section.
    for ( ( @adm, @prov ) ) { 
        printf qq[%s\n], $_; 
    }
    
    exit 0;
    

    Run it like:

    perl script.pl infile
    

    With following output:

    7
    11
    15
    9
    13
    17
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to read in the contents of a CSV file into some kind
I have some kind of problem with jQuery selectors. Let's say i want to
I have this .csv file: ID,GRADES,GPA,Teacher,State 3,C,2,Teacher3,MA 1,A,4,Teacher1,California And what I want to do
I have a CSV file that has lists of values for some fields. They're
I have kind of library which uses a bunch of its own perf counters.
I have a incomplete csv file that needs to be accurately updated, so there
I have a Web site (PHP) that generates a CSV file (text/csv) with the
I know I already have the Haskell Data.ByteString.Lazy function to split a CSV on
I have a CSV file I need to process which is a bit of
I have been looking for a way to reformat a CSV (Pipe separator) file

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.