topbanner_forum
  *

avatar image

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

Login with username, password and session length
  • Monday December 9, 2024, 12:09 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: Batch find/replace multiple strings in a single text file  (Read 6180 times)

wetsmellydog

  • Participant
  • Joined in 2007
  • *
  • Posts: 120
    • View Profile
    • Donate to Member
I work with CNC equipment that uses g-code to control the motion. It is a simple text file with machine specific codes and vector positioning. I use a program that outputs the code in a not so generic form and I also need to change some of the codes for use with a laser. I need to add spaces, replace characters ect and would like to do so with the least amount of manual repetition. I have used Notepad ++ but have not figured out how to accomplish this. Any ideas or programs to use would be great. Thanks!

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,644
    • View Profile
    • Donate to Member
Re: Batch find/replace multiple strings in a single text file
« Reply #1 on: March 17, 2015, 08:30 PM »
If you have is some before/after examples we could probably generate the regex for global replacements within Notepad++.

rjbull

  • Charter Member
  • Joined in 2005
  • ***
  • default avatar
  • Posts: 3,205
    • View Profile
    • Donate to Member
Re: Batch find/replace multiple strings in a single text file
« Reply #2 on: March 18, 2015, 04:44 PM »
You might try a free-standing bulk search-and-replace utility.  If you're happy with console mode and/or command lines, try the freeware MiniTrue, though on Windows it's probably better to use the version tweaked by Jason Hood here.  If you'd prefer WinGUI, take a look at the  two related programs HandyFile Find And Replace and Text Workbench.  I've used both MiniTrue and Text Workbench in the (distant) past.

AbteriX

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 1,149
    • View Profile
    • Donate to Member
Re: Batch find/replace multiple strings in a single text file
« Reply #3 on: March 19, 2015, 02:21 AM »
Such multiple replacements can be done also on console or via a script
by utilizing PowerShell, which is already there on each Win7/Win8 PC.

Examples:

$Origin = Get-Content .\test.txt

$LineWrap = $Origin -replace "(.{72}\b )", "`$1`r`n"

$Replacement = $LineWrap -replace "code\b", "program"

Set-Content .\test-new.txt -value $Replacement