Main Area and Open Discussion > General Software Discussion
Find/Replace different text strings in same text file
wetsmellydog:
I work with CNC machines that uses gcode for programming vector coordinates and machine function. One program does not output the code in the proper format so I have to manually add spaces, change letters for machine function ect. I would like to do this with a batch type function. I have used Notepad ++ put have not been able to figure out how to do so with it. I am open to all suggestions and programs. Thanks
Quick example, this text;
X00.00Y00.00
Z0.05
Would look like this after edit;
X00.00 Y00.00
S100 M3
The code could be from a few hundred lines to thousands of lines and it sure gets tedious to manually change.
Ath:
sed ?
Optionally running a Windows compiled version of that, and (nudge) using my SedTester NANY 2015 entry ?
MilesAhead:
sed ?
Optionally running a Windows compiled version of that, and (nudge) using my SedTester NANY 2015 entry ?
-Ath (March 19, 2015, 09:35 AM)
--- End quote ---
It sounds like it may be a good match for sed. The other approach that comes to mind would be associative arrays. Like if the Xxxxxx could be used as the key and the lines the OP wants pasted in after could be the data. Once the array is filled then it should be a simple matter of reading an input file and writing the output substituting the data from the array when a key line finds an array element for that key. With unique keys if the data is changed it could just be stuck at the end of the file and it would overwrite the previous element for that key when loading the assoc array.
Some programmers who use the Windows Scripting.Dictionary object tell me it can easilly hold a million elements or so on a machine with a few GB of ram.
AbteriX:
etsmellydog , why did you open a new thread ?
instead continue in your first one > https://www.donationcoder.com/forum/index.php?topic=40446.msg377969#msg377969
wetsmellydog:
etsmellydog , why did you open a new thread ?
instead continue in your first one > https://www.donationcoder.com/forum/index.php?topic=40446.msg377969#msg377969-AbteriX (March 19, 2015, 10:15 AM)
--- End quote ---
And I thought I was loosing my mind! I had posted originally from work but when I checked the forum, I could not find the post. I even did a search of my username to see what I had posted and to see if I had posted in another forum section but never turned up the OP. I did this both logged in and not logged in to see if there was another issue. I would welcome the moderator combining the two if possible.
Thanks AbteriX for finding my lost post!
Navigation
[0] Message Index
[#] Next page
Go to full version