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 9230839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:55:03+00:00 2026-06-18T05:55:03+00:00

I was trying to solve one problem for a while now but without success.

  • 0

I was trying to solve one problem for a while now but without success. In start it looks like a trivial issue but I have stacked with it…

Anyhow, I need to solve following problem. I have very large CSV file with lines in following format:

NUMBER(9);NUMBER(1);NUMBER(9-10);NUMBER(2);NUMBER(1);...;NUMBER(2);NUMBER(1);STRING;DATE(DD.MM.YYYY);NUMBER(1351)

for example:

517755369;1;0001303717;48;1;63;8;50;2;51;6;53;7;55;3;57;4;59;5;;;;;CALL;07.12.2012;1351

In each line after first tree fields I have 1 to 10 pairs NUMBER(2);NUMBER(1), followed by another three fields STRING;DATE(DD.MM.YYYY);NUMBER(1351).

I need to transform that file in file with following structure:

517755369;1;0001303717;48;1;CALL;07.12.2012;1351
517755369;1;0001303717;63;8;CALL;07.12.2012;1351
517755369;1;0001303717;50;2;CALL;07.12.2012;1351
517755369;1;0001303717;51;6;CALL;07.12.2012;1351
517755369;1;0001303717;53;7;CALL;07.12.2012;1351
517755369;1;0001303717;55;3;CALL;07.12.2012;1351
517755369;1;0001303717;57;4;CALL;07.12.2012;1351
517755369;1;0001303717;59;5;CALL;07.12.2012;1351`

So each line from input file should be transformed to as many lines as original line has NUMBER(2);NUMBER(1) pairs.

Here is a sample of input file:

517760344;2;000601301061;31;1;;;;;;;;;;;;;;;;;;;CALL;07.12.2012;1351
518855369;1;000601303717;48;1;63;8;50;2;51;6;53;7;55;3;57;4;59;5;;;;;CALL;07.12.2012;1351
519775067;1;000601300771;4;2;6;3;19;1;;;;;;;;;;;;;;;CALL;07.12.2012;1351
617773407;1;000603252922;13;1;17;2;27;3;;;;;;;;;;;;;;;CALL;07.12.2012;1351
717764779;1;000601304021;31;1;;;;;;;;;;;;;;;;;;;CALL;07.12.2012;1351`

In general I need some regexp that I can use with sed or awk (or some perl script I can run against input file). The original input file has roughly 1–1.5M records. This task should be finished as quickly as possible (up to 5 minutes for transformation).

Thanks

  • 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-18T05:55:05+00:00Added an answer on June 18, 2026 at 5:55 am

    Ideas from @Kenosis, but different interpretation of specs:

    use strict;
    use warnings;
    
    while (<DATA>) {
        chomp;
        my @fields = split /;/;
        my $f = 3;
        while ($fields[$f]) {
          print join( ';', @fields[0 .. 2, $f, $f + 1, -3 .. -1]), "\n";
          $f += 2;
        }
    }
    
    __DATA__
    517760344;2;000601301061;31;1;;;;;;;;;;;;;;;;;;;CALL;07.12.2012;1351
    518855369;1;000601303717;48;1;63;8;50;2;51;6;53;7;55;3;57;4;59;5;;;;;CALL;07.12.2012;1351
    519775067;1;000601300771;4;2;6;3;19;1;;;;;;;;;;;;;;;CALL;07.12.2012;1351
    617773407;1;000603252922;13;1;17;2;27;3;;;;;;;;;;;;;;;CALL;07.12.2012;1351
    717764779;1;000601304021;31;1;;;;;;;;;;;;;;;;;;;CALL;07.12.2012;1351
    

    output:

    perl 14528210.pl
    517760344;2;000601301061;31;1;CALL;07.12.2012;1351
    518855369;1;000601303717;48;1;CALL;07.12.2012;1351
    518855369;1;000601303717;63;8;CALL;07.12.2012;1351
    518855369;1;000601303717;50;2;CALL;07.12.2012;1351
    518855369;1;000601303717;51;6;CALL;07.12.2012;1351
    518855369;1;000601303717;53;7;CALL;07.12.2012;1351
    518855369;1;000601303717;55;3;CALL;07.12.2012;1351
    518855369;1;000601303717;57;4;CALL;07.12.2012;1351
    518855369;1;000601303717;59;5;CALL;07.12.2012;1351
    519775067;1;000601300771;4;2;CALL;07.12.2012;1351
    519775067;1;000601300771;6;3;CALL;07.12.2012;1351
    519775067;1;000601300771;19;1;CALL;07.12.2012;1351
    617773407;1;000603252922;13;1;CALL;07.12.2012;1351
    617773407;1;000603252922;17;2;CALL;07.12.2012;1351
    617773407;1;000603252922;27;3;CALL;07.12.2012;1351
    717764779;1;000601304021;31;1;CALL;07.12.2012;1351
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to solve this problem for a while now and I
I am trying to solve one problem from on-line judging system. I have a
I've been trying to solve this problem for a while now, and I'm at
I'm trying to solve this problem for a week now and I have tested
I'm new to C and I'm trying to solve one of the exercise problem
Trying to solve an issue for someone else and instead have run into my
Trying to solve a problem with templatetags. I have two templatetags: @register.inclusion_tag('directory/_alphabet.html') def alphabet_list(names):
Trying to solve this problem . I would like to learn how the bootstrapper
I'm trying to solve the following problem in Redis. I have a list that
I am trying to solve this problem http://www.spoj.pl/problems/PEBBMOV/ . I think I have the

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.