topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Thursday March 28, 2024, 8:27 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Find/Replace different text strings in same text file  (Read 5364 times)

wetsmellydog

  • Participant
  • Joined in 2007
  • *
  • Posts: 120
    • View Profile
    • Donate to Member
Find/Replace different text strings in same text file
« on: March 19, 2015, 09:31 AM »
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

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 3,612
    • View Profile
    • Donate to Member
Re: Find/Replace different text strings in same text file
« Reply #1 on: March 19, 2015, 09:35 AM »
sed ?

Optionally running a Windows compiled version of that, and (nudge) using my SedTester NANY 2015 entry ?

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • View Profile
    • Donate to Member
Re: Find/Replace different text strings in same text file
« Reply #2 on: March 19, 2015, 10:04 AM »
sed ?

Optionally running a Windows compiled version of that, and (nudge) using my SedTester NANY 2015 entry ?

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

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 1,149
    • View Profile
    • Donate to Member
Re: Find/Replace different text strings in same text file
« Reply #3 on: March 19, 2015, 10:15 AM »
etsmellydog , why did  you open a new thread ?

instead continue in your first one  > https://www.donation....msg377969#msg377969


 

wetsmellydog

  • Participant
  • Joined in 2007
  • *
  • Posts: 120
    • View Profile
    • Donate to Member
Re: Find/Replace different text strings in same text file
« Reply #4 on: March 19, 2015, 11:10 AM »
etsmellydog , why did  you open a new thread ?

instead continue in your first one  > https://www.donation....msg377969#msg377969

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!
 

wetsmellydog

  • Participant
  • Joined in 2007
  • *
  • Posts: 120
    • View Profile
    • Donate to Member
Re: Find/Replace different text strings in same text file
« Reply #5 on: March 21, 2015, 01:27 AM »
Thanks for all the suggestions. SED looks great and powerful but I will have to get more acquainted with the usage. After searching for more information on SED, I came across this program Replace Text v2.2 from ecobyte software. It can be found here http://www.ecobyte.com/replacetext/ It also happens to be free.

It does exactly what I need and is very fast.

MilesAhead

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 7,736
    • View Profile
    • Donate to Member
Re: Find/Replace different text strings in same text file
« Reply #6 on: March 21, 2015, 07:20 AM »
Thanks for all the suggestions. SED looks great and powerful but I will have to get more acquainted with the usage. After searching for more information on SED, I came across this program Replace Text v2.2 from ecobyte software. It can be found here http://www.ecobyte.com/replacetext/ It also happens to be free.

It does exactly what I need and is very fast.
-wetsmellydog (March 21, 2015, 01:27 AM)

It looks like a very interesting utility.  I wish it specified what the "known problems" with Windows 7 were.  With a search string like "replace text" it's tough to find out what the bugs were.

Edit:  One thing could be it has the old .hlp format help file.  The WinHlp32.exe stub on Vista and later has to be updated in order to read the help.  I just updated mine on W8.  Someone pointed out the Windows Update that replaces the stub.

Edit2:  Anyone else on W8 the stub replacement can be downloaded here:
https://support.micr....com/en-us/kb/917607

If you have automatic updates enabled it may be academic.  But I keep mine turned off.

« Last Edit: March 21, 2015, 09:55 AM by MilesAhead »