Imports System.IO
Module Module1
Dim inputfile As String = "C:\Users\Kimputer\Documents\transactioncode.txt"
Dim outputpath As String = "C:\Users\Kimputer\Documents"
Sub Main()
Dim sr As New StreamReader(inputfile)
Do Until sr.EndOfStream
Dim line = sr.ReadLine
Dim number = (Left(Mid(line, 33), 3))
Dim sw As New StreamWriter(Path.Combine(outputpath, "Record" & number.ToString & ".txt"))
sw.WriteLine(line)
sw.Close()
sw = Nothing
Loop
End Sub
End Module
@echo off
for /f "tokens=*" %%a in (transactioncode.txt) do call :processline %%a
goto :eof
:processLine
set str=%2
set str=%str:~0,3%
echo %1 %2 > Record%str%.txt
goto :eof
:eof
@echo off
SETLOCAL DisableDelayedExpansion
FOR /F "usebackq delims=" %%a in (`"findstr /n ^^ test.txt"`) do (
set "line=%%a"
call :processLine line
)
goto :eof
:processLine
SETLOCAL EnableDelayedExpansion
set "line=!%1!"
set "line=!line:*:=!"
echo %line:~35% >> Record%line:~32,3%.txt
ENDLOCAL
goto :eof
@echo off
for /f "tokens=*" %%a in (transactioncode.txt) do call :processline %%a
goto :eof
:processLine
set str=%2
set str=%str:~0,3%
echo %1 %2 >> Record%str%.txt
goto :eof
:eof
Use the '>>' in the echo line as opposed to '>'.
Topics applied: Visual Basic Classic, .NET Programming, Windows Batch
Topics removed: Visual Basic Classic, .NET Programming