Main Area and Open Discussion > General Software Discussion
Batch find/replace multiple strings in a single text file
(1/1)
wetsmellydog:
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:
If you have is some before/after examples we could probably generate the regex for global replacements within Notepad++.
rjbull:
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:
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
Navigation
[0] Message Index
Go to full version