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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:53:00+00:00 2026-06-17T08:53:00+00:00

I have a text file that I need to append to be able to

  • 0

I have a text file that I need to append to be able to import into my database. There are some 4800 odd lines in the text file. The data is under. Can someone help me with a python script that will:

  1. Read the file
  2. Remove everything except lines with NDC,xxxxx-xxxx-xx
  3. Write a new file with the data NDC,XXXXX-XXXX-XX

Notice that the NDC is some time in XXXX-XXXX-XX format and sometimes XXXXX-XXXX-XX format.

Here is some data:

NDC,0065-0795-50

5.25667
48320,2
NDC,0517-2650-25

0.0411

NDC,51079-190-20

0.1582

NDC,0603-5450-21

0.7924
  • 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-17T08:53:01+00:00Added an answer on June 17, 2026 at 8:53 am
    with open(inpath, 'r') as infile, open(outpath, 'w') as outfile:
        for line in infile:
            if 'NDC,' in line:
                outfile.write(line)
    

    This makes some assumptions:

    • There is never any random text with 'NDC,' in it except for your values. If that’s not true, you may want to write a smarter test, possibly using regular expressions.
    • You want to write the entire line if there’s an 'NDC,', not just that part of the line. If that’s not true, it should be easy to adjust—especially if you’ve done the above (because then you’ll just write, e.g., the re matches instead of the line).
    • And so on…

    Since your question was so vague, there’s no alternative but making guesses like that, and likely at least one of them will be wrong.

    But this shows you what the structure of the program looks like, and you should be able to fill in the gaps yourself. Try it, then come back and ask for help if you get stuck.

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

Sidebar

Related Questions

I have a text file dump that I need to convert to a delimited
I have a text file having words that i need to validate. After following
I have a text file that contains some strings separated by ,. Strings are
I have data in text file and I need to store it in database
I have a log file that contains a lot of text, some of it
I'd like to append some text from my iPhone app, to a file that
What I have is an extremely large text file that needs to go into
I have Text file that contains data separated with a comma , . How
I have a text file that I want to edit by rewriting it to
I have a text file that's appended to over time and periodically I want

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.