Would this be a difficult program to write? Details inside

DaTT

Garage Moderator
Moderator
Feb 13, 2003
13,295
118
106
I need a program to read through a text file and make changes upon certain conditions and spit out a new file. Here is the example below.

Take this text file
NEZ 13000 4860271.330 683259.150 92.391 "DCB"
NEZ 13001 4860271.057 683258.136 92.418 "B GO"
NEZ 13002 4860260.096 683260.271 92.683 "GO"
NEZ 13003 4860293.237 683255.697 92.738 "GO"
NEZ 13004 4860318.665 683253.699 92.434 "GO"
NEZ 13005 4860319.888 683255.541 92.423 "CB"
NEZ 13006 4860327.588 683250.237 92.557 "B EP"
NEZ 13007 4860332.990 683248.822 91.965 "B BD"
NEZ 13008 4860338.890 683270.007 91.919 "BD"
NEZ 13009 4860333.877 683272.528 92.534 "EP"
NEZ 13010 4860324.544 683274.007 92.337 "GO"
NEZ 13011 4860296.177 683276.034 92.416 "GO"
NEZ 13012 4860272.743 683277.075 92.369 "GO"
NEZ 13013 4860263.201 683277.590 92.347 "B EP"
NEZ 13014 4860260.877 683277.765 92.429 "B GO"
NEZ 13015 4860262.766 683301.026 92.175 "GO"
NEZ 13016 4860264.814 683300.366 92.038 "EP"
NEZ 13017 4860274.145 683299.075 92.101 "GO"

And make it look like this:
NEZ 13000 4860271.330 683259.150 92.391 "DCB"
BEG GO
NEZ 13001 4860271.057 683258.136 92.418 "GO"
NEZ 13002 4860260.096 683260.271 92.683 "GO"
NEZ 13003 4860293.237 683255.697 92.738 "GO"
NEZ 13004 4860318.665 683253.699 92.434 "GO"
END
NEZ 13005 4860319.888 683255.541 92.423 "CB"
BEG EP
NEZ 13006 4860327.588 683250.237 92.557 "EP"
END
BEG BD
NEZ 13007 4860332.990 683248.822 91.965 "BD"
NEZ 13008 4860338.890 683270.007 91.919 "BD"
END
CONT EP
NEZ 13009 4860333.877 683272.528 92.534 "EP"
END
CONT GO
NEZ 13010 4860324.544 683274.007 92.337 "GO"
NEZ 13011 4860296.177 683276.034 92.416 "GO"
NEZ 13012 4860272.743 683277.075 92.369 "GO"
END
BEG EP
NEZ 13013 4860263.201 683277.590 92.347 "EP"
END
BEG GO
NEZ 13014 4860260.877 683277.765 92.429 "GO"
NEZ 13015 4860262.766 683301.026 92.175 "GO"
END
CONT EP
NEZ 13016 4860264.814 683300.366 92.038 "EP"
END
CONT GO
NEZ 13017 4860274.145 683299.075 92.101 "GO"
END

Basically it must search the values in the quotations and make necessary changes to the code in the quotations and add a BEG *** command above where the code is B **and an END command after (providing the next code in the quotation is not the same value.) And if there is another code of the same value a few lines down, it must add the CONT *** command above it.

When there is a B *** code in the quotations, it must also remove the B and the space in the portion within the quotations.

Is this doable with relative ease?
 
Last edited:

purbeast0

No Lifer
Sep 13, 2001
53,262
6,108
126
from what you have said, although i think there would be more details needed, that seems pretty basic/easy to make. it would basically just be reading in the file, line by line, and doing regular expression matching on the line.

if it sound something you are looking for, it would do what is required and add that to the output file. if it doesn't find anything you just append that line to the new file.

that is the general gist of it.

depending how complicated the "rules" you have are, you may have to store it all in an object so you can manipulate things before/after the current line, and then just dump that object out to a text file at the end of the program.
 

DaTT

Garage Moderator
Moderator
Feb 13, 2003
13,295
118
106
from what you have said, although i think there would be more details needed, that seems pretty basic/easy to make. it would basically just be reading in the file, line by line, and doing regular expression matching on the line.

if it sound something you are looking for, it would do what is required and add that to the output file. if it doesn't find anything you just append that line to the new file.

that is the general gist of it.

depending how complicated the "rules" you have are, you may have to store it all in an object so you can manipulate things before/after the current line, and then just dump that object out to a text file at the end of the program.

That sounds exactly like what I would require. The rules are very simple, look within the quotations for any code starting with B and a space. The only complicated thing, imo, would be that the program would have to remember certain things like when it first sees a B space, the next time it came across the same code without the B space, it would have to add CONT instead of BEG, and of course the END command as well. And it may have to remember several different parameters at the same time.

What could I use to write this? Or rather attempt to write this?
 

Train

Lifer
Jun 22, 2000
13,578
73
91
www.bing.com
You're basically doing a GROUP BY

Why not suck it into Access, group them and spit it back out?

What is the output used for? Another program needs them in that particular format?
 

purbeast0

No Lifer
Sep 13, 2001
53,262
6,108
126
That sounds exactly like what I would require. The rules are very simple, look within the quotations for any code starting with B and a space. The only complicated thing, imo, would be that the program would have to remember certain things like when it first sees a B space, the next time it came across the same code without the B space, it would have to add CONT instead of BEG, and of course the END command as well. And it may have to remember several different parameters at the same time.

What could I use to write this? Or rather attempt to write this?

if it were me, i'd do it in java just because i'm familiar with how Strings and file input/output works in java, and have written some tools to input data and output them to text files in a specific format. java also has really easy ways to display file choosers and stuff like that, if you go with making an actual gui for it. just depends how fancy you want it. it could also have no gui and you just have 2 arguments with the command to run it, one input file, and one the output file.
 

DaTT

Garage Moderator
Moderator
Feb 13, 2003
13,295
118
106
You're basically doing a GROUP BY

Why not suck it into Access, group them and spit it back out?

What is the output used for? Another program needs them in that particular format?

It is a survey file and it is used by AutoCAD to string lines together. Each line is numbered and the numbering sequence cannot be altered otherwise the linework will not look right...or work at all for that matter.

We just got new GPS equipment and it is not converting the files like the old equipment did. I am exercising my options here to save me time. I just spent the better part of today going through around 6000 lines and manually inputting the BEG, CONT and END commands. It was tedious to say the least.
 

Train

Lifer
Jun 22, 2000
13,578
73
91
www.bing.com
It is a survey file and it is used by AutoCAD to string lines together. Each line is numbered and the numbering sequence cannot be altered otherwise the linework will not look right...or work at all for that matter.

We just got new GPS equipment and it is not converting the files like the old equipment did. I am exercising my options here to save me time. I just spent the better part of today going through around 6000 lines and manually inputting the BEG, CONT and END commands. It was tedious to say the least.

That sucks. Probably best to write a console app in .Net/Java/Python
 

DaTT

Garage Moderator
Moderator
Feb 13, 2003
13,295
118
106
What would be the best "easy-to-use" preferably free program to use to write this with....Extreme novice here.
 

DaTT

Garage Moderator
Moderator
Feb 13, 2003
13,295
118
106
Thanks Purebeast and Train. I'm sure if I decide to go through with this, there will be many more threads to follow :)

The trick is now, getting the government to pay for my time in writing this.
 

Cogman

Lifer
Sep 19, 2000
10,283
134
106
Python. No need for a complex IDE. Your description looks like this SHOULD be easy (50 lines max).
 

Train

Lifer
Jun 22, 2000
13,578
73
91
www.bing.com
Python. No need for a complex IDE. Your description looks like this SHOULD be easy (50 lines max).

Complex IDE? He can hit run and it goes. If there's errors he can click on them and it will take him to the error.

You want him to learn how to compile via command line with Python?

On windows, getting started with Python is infinitely more complex than just starting a new project in VS.
 

Cogman

Lifer
Sep 19, 2000
10,283
134
106
Complex IDE? He can hit run and it goes. If there's errors he can click on them and it will take him to the error.

You want him to learn how to compile via command line with Python?

On windows, getting started with Python is infinitely more complex than just starting a new project in VS.

Step 1, download python
Step 2, write python
Step 3, type in "py myScript.py"

How is that complex? The most complex part of this is making sure python is in your path which is an option for the installer.

For visual studios you have to create the project. Choose the right template to get started with. Figure out how to get the file you want into the right path. etc. There are tons of options and directions you can go and not all of them are wrong.

With the python approach you can put the script right next to the files you want to deal with and pass those files in as a parameter to the script. Easy peasy.

You get the added bonus that python is really pretty good about handling IO with files/etc

https://docs.python.org/3.3/tutorial/inputoutput.html



If I were doing this as a serious "This will be complex and take a lot of time to write" sort of thing, I would choose C#/Java. But for a 1 and done sort of script, it is hard to beat python. No random project files/build processes/etc You simply run the script. You can do it all in notepad++ or sublime.
 

BoberFett

Lifer
Oct 9, 1999
37,562
9
81
For simple file manipulation in Windows, I love having an old copy of VB6 around. So easy to write a few lines and step through for debug.

It could be done using VBS too, just use the file objects.
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
Do you already know any languages?

This could be done using PHP, BASIC, C/C++, Pascal, Java, ... almost anything that can open one file, read lines, write to a new file.
 

Net

Golden Member
Aug 30, 2003
1,592
2
81
i agree python. if you need to learn something to solve this problem then learn python. python is great for doing things like this in a few lines.
 

DaTT

Garage Moderator
Moderator
Feb 13, 2003
13,295
118
106
Do you already know any languages?

This could be done using PHP, BASIC, C/C++, Pascal, Java, ... almost anything that can open one file, read lines, write to a new file.

I do not know any languages.
 

Train

Lifer
Jun 22, 2000
13,578
73
91
www.bing.com
Step 1, download python
Step 2, write python
Step 3, type in "py myScript.py"

How is that complex? The most complex part of this is making sure python is in your path which is an option for the installer.

For visual studios you have to create the project. Choose the right template to get started with. Figure out how to get the file you want into the right path. etc. There are tons of options and directions you can go and not all of them are wrong.

With the python approach you can put the script right next to the files you want to deal with and pass those files in as a parameter to the script. Easy peasy.

You get the added bonus that python is really pretty good about handling IO with files/etc

https://docs.python.org/3.3/tutorial/inputoutput.html



If I were doing this as a serious "This will be complex and take a lot of time to write" sort of thing, I would choose C#/Java. But for a 1 and done sort of script, it is hard to beat python. No random project files/build processes/etc You simply run the script. You can do it all in notepad++ or sublime.

Write python in what? Notepad?

With no syntax highlighting, no intellisense, no debugging. Gimme a break.