VB Code:
Dim sContent As String
Dim iInputFile As Integer
Dim iOutputFile As Integer
Dim iFirstSpace As Integer
Dim iLineNumber As Integer
iInputFile = FreeFile()
Open "E:\MC\sometext.txt" For Input As #iInputFile
iOutputFile = FreeFile()
Open "E:\MC\anotherFile.txt" For Output As #iOutputFile
Do While Not EOF(iInputFile)
Line Input #iInputFile, sContent
Print #iOutputFile, sContent
iFirstSpace = InStr(sContent, " ") ' Find the position of the first space
If Mid$(sContent, iFirstSpace + 1, 1) = "Z" Then ' Check the first character after the first space
iLineNumber = CInt(Mid$(sContent, 2, iFirstSpace - 2)) + 1 ' Get the line number, then add 1
Print #iOutputFile, "N" & iLineNumber & " G04 P1" ' Create and print the new line
End If
Loop
Close #iInputFile
Close #iOutputFile