Reputation: 25
I want to erase the line numbering inside an ascii code file. The numbering starts with the Letter "N" and is followed by numbers as in example below.
N4980 G01 X = 0.75 Y = 14.97 Z = 0.07
N5000 G01 X = 1.75 Y = 14.97 Z = 0.07
N5020 G01 X = 1.75 Y = 22.00 Z = 0.07
N5030 G01 X = 0.75 Y = 14.97 Z = 0.07
N5060 G01 X = 32.75 Y = 14.97 Z = 0.07
i used powershell to replace individual strings but not a sequence of numbers. does anyone have a solution for this?
thanks!
Upvotes: 0
Views: 40
Reputation: 174485
Read the file with Get-Content
, use -replace
to (conditionally) replace the line number, then pipe the whole thing to Set-Content
to write it back to disk:
# read the whole file
$lines = Get-Content .\file.txt
# replace any leading `NXXXX ` sequence and write back to the file
$lines -replace '^N\d+\s+' |Set-Content .\file.txt
Upvotes: 1