Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

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

Login with username, password and session length
  • December 06, 2016, 08:07:39 AM
  • Proudly celebrating 10 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 1108 times)

wetsmellydog

  • Participant
  • Joined in 2007
  • *
  • default avatar
  • Posts: 104
    • View Profile
    • Donate to Member
Batch find/replace multiple strings in a single text file
« on: March 17, 2015, 07:44:09 PM »
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: 4,474
    • View Profile
    • Donate to Member
Re: Batch find/replace multiple strings in a single text file
« Reply #1 on: March 17, 2015, 08:30:34 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: 2,925
    • View Profile
    • Donate to Member
Re: Batch find/replace multiple strings in a single text file
« Reply #2 on: March 18, 2015, 04:44:04 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,115
    • View Profile
    • Donate to Member
Re: Batch find/replace multiple strings in a single text file
« Reply #3 on: March 19, 2015, 02:21:42 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