Jump to content

CSV Line Replacement

nicknails

I'll preface by saying that I am not good with programming. I have a directory of CSV files, all are very similar. One we'll call a "master" csv file. I need to be able to change the master CSV (roughly the 1st 15 lines or so) and then propagate those changes to the remainder of the CSV files. Right now there's only a dozen or so, but there will be over a hundred in the not too distant future. I'm using a windows PC if that makes a difference.

Link to comment
Share on other sites

Link to post
Share on other sites

7 hours ago, nicknails said:

I'll preface by saying that I am not good with programming. I have a directory of CSV files, all are very similar. One we'll call a "master" csv file. I need to be able to change the master CSV (roughly the 1st 15 lines or so) and then propagate those changes to the remainder of the CSV files. Right now there's only a dozen or so, but there will be over a hundred in the not too distant future. I'm using a windows PC if that makes a difference.

You need a way to tell the difference between two files, the old master and the modified master. Then you need a way to link those changes from the master to the other CSV files.

But the real question here is, why do you want a system where you make updates to one file, but read them from a collection of other files? Have you and/or your team considered using something more coherent?

ENCRYPTION IS NOT A CRIME

Link to comment
Share on other sites

Link to post
Share on other sites

On 1/31/2020 at 1:06 PM, nicknails said:

I'll preface by saying that I am not good with programming. I have a directory of CSV files, all are very similar. One we'll call a "master" csv file. I need to be able to change the master CSV (roughly the 1st 15 lines or so) and then propagate those changes to the remainder of the CSV files. Right now there's only a dozen or so, but there will be over a hundred in the not too distant future. I'm using a windows PC if that makes a difference.

  1. You need to define what type of changes you're making that are being propagated to each of the CSV files.  Are the changes you're making dependent upon what's already in each of the files, like say checking if some value in one of the columns contains a certain word and replacing it, or adding 10 to a number in the 5th column, or are the changes made going to be constant, so just completely disregarding whatever is in the other files, like changing a field to have a set value.
  2. You might not like it, but you are going to have read in the entire file into a variable, make the necessary changes, and resave it to another file.  For each of your files.  I would also highly recommend that you don't overwrite your existing file until after the other file is saved.  So once you make your changes:
    a - Save that data to a temporary file (leaving the existing file alone).
    b - Change the name of the original file to something like <original_filename>.csv.old
    c - Change the name of the new file to the filename you need it to be
    d - Then delete the old file
    This will protect you in case you have a power outage of the system hang or crashes.

Similar to straight_stewie, I would also like to say that if you're doing this to avoid having to deal with setting up and maintaining a database, then you cannot comprehend just how big of a mistake you are making, and just how much you are shooting yourself in the foot.  A few of our clients use products developed by people who decided to make their own "database" rather than use an existing one.  They are always horribly slow, extremely crash prone, and lack all of the features that have been added to databases over the last half a century.

Yes, there is a bit of a learning curve, not to mention the time necessary to get everything setup and working, but having dealt with both the good, the bad, and the ugly ones, I can promise you it's worth it.

 

Best of luck to you.  I have a feeling your going to need it.

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

The usage for this is a pick and place machine. Each PCB has it's own file and the feeder information is included in that file. If I change feeder information, I have to change it on every PCB file. So now I have a "master" file that I use and update anytime there is a feeder change. I want to update all the PCB's files from that master file.

 

I would have to replace the first 15 lines or so in each file. It's not a search and replace, it would be delete the lines and copy in replacement lines.

Link to comment
Share on other sites

Link to post
Share on other sites

2 hours ago, nicknails said:

The usage for this is a pick and place machine. Each PCB has it's own file and the feeder information is included in that file. If I change feeder information, I have to change it on every PCB file. So now I have a "master" file that I use and update anytime there is a feeder change. I want to update all the PCB's files from that master file.

 

I would have to replace the first 15 lines or so in each file. It's not a search and replace, it would be delete the lines and copy in replacement lines.

Oh that's significantly easier.

 

To clarify, I'm operating on the assumption that the feeder information is always the same in each picker program.

 

What you can do is have a single feeder information file, and then your individual picker program files.

When you go to build the picker program files into whatever format the pick-and-place machine needs, simply add to your build script an action that inserts the text from the feeder information file into the picker program file before compiling the program.

I assume, possibly wrongly, that at some phase in the build cycle your build tool has a linker like tool, where you can reference code from outside files. If that's the case, just use that, and then use a linker directive to include the feeder information code.

 

This is a very common way to organize maintainable code, and there is some tool present to handle this for you in virtually every non-toy language and programming environment available.

For example, the import tool in Python, the using directive in C#, and the include directive in C++:

 

Python

from module import thing

C#

using Namespace.Namespace...OptionalObject;

C++

#include <filePath>

 

ENCRYPTION IS NOT A CRIME

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×