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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:33:28+00:00 2026-05-12T05:33:28+00:00

I have a set of 4 massive CSV files that I need to modify.

  • 0

I have a set of 4 massive CSV files that I need to modify. What I need to do is match this expression /^(.*),,/ copy the atom then prepend it to every subsequent line until the atom is matched again. Then I need to rinse and repeat until the end of the file (each file has approx 25k lines in it). Finally I need to go back through and remove the first atom.

I would like to use sed for this if it’s possible. I tried doing it with vim but couldn’t get the regex right. Any help would be greatly appreciated. An example is illustrated below:

Before:

0917,,
,882-1273,1
,95F 9475,1
,276-080,1
,40K 0080,1
,275-690A,1
,TX-2311,3
,TX-3351,4
,B-07432,1
,B-6901,1
,23-753,1
,02F 4307,1
,5.1K QBK-ND,1
,0944-026,1
,0944-027,1
,0944-004,1
,0944-056,1
,0944-057,1
,0944-082,1
,0944-024,1
,0944-025,1
,0944-102,4
,LOR 102,1
0918,,
,CJ1085,1
,1352-152,4
,DMS3102A-18-,1
,6-32 KEP,7
,6-32 X 3/4,4
,6-32X1/2,4
,1251-102,8
,Oct-32,4
,10-32 SAE,8

After:

0917,882-1273,1
0917,95F 9475,1
0917,276-080,1
0917,40K 0080,1
0917,275-690A,1
0917,TX-2311,3
0917,TX-3351,4
0917,B-07432,1
0917,B-6901,1
0917,23-753,1
0917,02F 4307,1
0917,5.1K QBK-ND,1
0917,0944-026,1
0917,0944-027,1
0917,0944-004,1
0917,0944-056,1
0917,0944-057,1
0917,0944-082,1
0917,0944-024,1
0917,0944-025,1
0917,0944-102,4
0917,LOR 102,1
0918,CJ1085,1
0918,1352-152,4
0918,DMS3102A-18-,1
0918,6-32 KEP,7
0918,6-32 X 3/4,4
0918,6-32X1/2,4
0918,1251-102,8
0918,Oct-32,4
0918,10-32 SAE,8
  • 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-05-12T05:33:29+00:00Added an answer on May 12, 2026 at 5:33 am

    The program (python)

    import csv
    infile=file("in","r")
    outfile=file("out","w")
    reader = csv.reader(infile , dialect='excel')
    writer = csv.writer(outfile , dialect='excel')
    current_header=""
    for inrow in reader:
        if len(inrow[0].strip()) != 0:
            current_header = inrow[0]
            continue
    
        writer.writerow([current_header]+inrow[1:])
    
    infile.close()
    outfile.close()
    print "done"
    

    The input

    0917,,
    ,882-1273,1
    ,95F 9475,1
    ,276-080,1
    ,40K 0080,1
    ,275-690A,1
    ,TX-2311,3
    ,TX-3351,4
    ,B-07432,1
    ,B-6901,1
    ,23-753,1
    ,02F 4307,1
    ,5.1K QBK-ND,1
    ,0944-026,1
    ,0944-027,1
    ,0944-004,1
    ,0944-056,1
    ,0944-057,1
    ,0944-082,1
    ,0944-024,1
    ,0944-025,1
    ,0944-102,4
    ,LOR 102,1
    0918,,
    ,CJ1085,1
    ,1352-152,4
    ,DMS3102A-18-,1
    ,6-32 KEP,7
    ,6-32 X 3/4,4
    ,6-32X1/2,4
    ,1251-102,8
    ,Oct-32,4
    ,10-32 SAE,8
    

    The output

    0917,882-1273,1
    0917,95F 9475,1
    0917,276-080,1
    0917,40K 0080,1
    0917,275-690A,1
    0917,TX-2311,3
    0917,TX-3351,4
    0917,B-07432,1
    0917,B-6901,1
    0917,23-753,1
    0917,02F 4307,1
    0917,5.1K QBK-ND,1
    0917,0944-026,1
    0917,0944-027,1
    0917,0944-004,1
    0917,0944-056,1
    0917,0944-057,1
    0917,0944-082,1
    0917,0944-024,1
    0917,0944-025,1
    0917,0944-102,4
    0917,LOR 102,1
    0918,CJ1085,1
    0918,1352-152,4
    0918,DMS3102A-18-,1
    0918,6-32 KEP,7
    0918,6-32 X 3/4,4
    0918,6-32X1/2,4
    0918,1251-102,8
    0918,Oct-32,4
    0918,10-32 SAE,8
    

    Have fun

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This has been killing me - I have a massive file that I need
I have a massive, unfamiliar Java codebase that I need to use in one
I have set up a Django application that uses images. I think I have
I got a backend web service containing massive amounts of data that I have
I have a massive collection of methods that I want to shape into a
I have a massive amount of data that needs to be read from mysql,
I have a mysql database set as utf-8, and csv data set as utf-8,
I have always hoped and assumed that it is not - that set theory
We have set up a system where notifications get sent to a user with
I have set a canvas' background to an image of a company logo. I

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.