# [SOLVED] strip line numbers in g code



## sobeit (Nov 11, 2007)

I am looking for a utility that will strip line numbers in a text file and ignore lines that do not have line numbers. the one we are currently using is 16 bit and not compatible with win7. compatibility mode does not work and we are about to lose the last xp computer. 

the line numbers are the nXXX. They need to be deleted from a file that will have over 100000 lines but not every line will have a line number. anyone know of a utility that will do this?

sample
%
:O1000
n010 T1 M6
n011 G0 G90 G40 G21 G17 G94 G80
n012 G54 X-75 Y-25 S500 M3 (Start Point)
n013 G43 Z100 H1
n014 Z5
G1 Z-20 F100
X-50 M8 
X0 Y50 
X50 Y0 
X0 Y-50 
X-50 Y0 
Y25 
X-75 
G0 Z100
M30


----------



## AlbertMC2 (Jul 15, 2010)

*Re: strip line numbers in g code*

You just need a script to do this.

1)
In vbscript: (copy code and save as name.vbs)

```
Set objArgs = WScript.Arguments 
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objRE = New RegExp

If objArgs.Count = 1 Then
	strFile = objArgs(0)
	Set objFile = objFS.GetFile(strFile)
	strTemp = objFS.GetParentFolderName(objFile) & "\temp.txt"
else
	strFile = "c:\test\test.txt"
	strTemp = "c:\test\temp.txt"
End If

Set objFile = objFS.OpenTextFile(strFile)
Set objOutFile = objFS.CreateTextFile(strTemp,True) 

With objRE
    .Pattern    = "^n[0-9]{3} \b"
    .IgnoreCase = True
    .Global     = False
End With

Do Until objFile.AtEndOfStream
	strLine = objFile.ReadLine
	If objRE.Test( strLine ) Then 
		result = objRE.Replace(strLine, "")
		objOutFile.WriteLine(result)
	Else
		objOutFile.WriteLine(strLine)
	End If
Loop

Set objRE = Nothing
objOutFile.Close
objFile.Close
objFS.DeleteFile(strFile)
objFS.CopyFile strTemp,strFile,overwrite
objFS.DeleteFile(strTemp)
```
You can just drag and drop your file onto the newly created VBS file.

2)
Else here is a powershell script. I have just started with powershell so it might not be fast or the best possible way to do this.
Copy the code and save it as script.ps1
to run go to *start *-> *run *-> type in 
*powershell -file "c:\users\user\desktop\script.ps1"*


```
$file = "c:\test\1.txt"
$content = Get-Content $file
if ( $content -match "^n[0-9]{3} \b" ) {
        $content -replace "^n[0-9]{3} \b", "" |
        Set-Content $file     
 } 
else {
        Add-Content $file ""
}
```
where "c:\test\1.txt" is the path and name of your file

3)
Lastly you could do this in Notepad++
Open document -> Search -> Replace
Search for *^n[0-9]{3} *
Note there must be a space after the {3}
And replace it with nothing
Make sure you select Regular Expression
Then replace all.


----------



## sobeit (Nov 11, 2007)

*Re: strip line numbers in g code*

thanks for the scripts. I will give them a try monday. I don't know why I did not think about the wordpad one - I guess I did not know you can replace text with nothing  don't know why the person from our computer department didn't think of that either. all they did was to try a bunch of dos emulators.


----------



## AceInfinity (Jan 21, 2012)

*Re: strip line numbers in g code*

You don't even need a script, just use a good text editor like Notepad++ or SublimeText2, Ctrl+H (for replace) make sure Regex is enabled, then create a pattern to look for numeric characters at the beginning of a line, replace them with "" if you want to get rid of them...

A program for this is simple as well, you could use substrings after iterating line by line, otherwise compiled regex for instance, and strip out what isn't needed.


----------



## sobeit (Nov 11, 2007)

Notepad++ works perfectly, thanks.


----------

