|
Answer» Hello everyone.
I've got a huge list of post codes that havent got any spaces in them. there are 2 formats, for example
A12 3BC or A1 2BC so ideally I need something that will add a space 3 characters from the end of each line. The list has been put in notepad which caused problems viewing it from the START. Its a very big list. WOULD be very grateful if anyone can help.
ThanksAre all the lines 5 letters? If so it would be much easyer.
Untested: Code: [Select]@echo off setlocal EnableDelayedExpansion for /f "delims=" %%A in ('type "a.txt"') do call :loop exit /b
:loop set a=0 set line=%1 set char=0 :loop.1 REM find char in line if not "!line:~%a%,1!"=="" ( set /a char+=1 set /a a+=1 goto :loop.1 ) REM find 3 spaces back set /a end=%char%-3 set a=0 set line2= :loop.2 REM set line2 set workingChar=!line:~%a%,1! if %a% == %end% ( set line2=%line2% %workingChar% ) else ( set line2=%line2%%workingChar% ) if not %a% == %char% goto :loop.2 echo %line2% >>file2.txt goto :eof Lemonilla, you don't ever pass the contents off to the loop.
@OP, try this:
Code: [Select]@echo off setlocal enabledelayedexpansion for /f "delims=" %%a in (a.txt) do ( set line=%%a set line=!line: =! set line=!line:~0,-3! !line:~-3! echo !line!>>newpost.txt ) It removes any spaces from each line, then takes EVERYTHING but the last 3 characters, ADDS a space, then tacks on the last 3 characters to the end. It's all put into a new file called "newpost.txt".
|