changing text content

  • Thread starter Thread starter Daniel
  • Start date Start date
D

Daniel

I have several delimited text files that have numbers that correspond to
crop fields that my company works with. There are thousands of the fields
and each have different numbers assigned to them. The number is made up of
a 5 digit unit and then a 4 digit field number like so: 413072536. When
the 4 digit field number has only 3 digits, it is like so 0123, but the
extracted data doesn't pad the 0 in front of the other 3 numbers. Here is
part of my file:

40603604,0
40603605,0
406031201,0
406031301,0

I need a batch that will add a 0 to the 6th place if the number is only 8
digits, and if it is 9 digits, leave it alone. Any help would be
appreciated for I have several thousands of these to do.

Daniel
 
Daniel said:
I have several delimited text files that have numbers that correspond to
crop fields that my company works with. There are thousands of the fields
and each have different numbers assigned to them. The number is made up of
a 5 digit unit and then a 4 digit field number like so: 413072536. When
the 4 digit field number has only 3 digits, it is like so 0123, but the
extracted data doesn't pad the 0 in front of the other 3 numbers. Here is
part of my file:

40603604,0
40603605,0
406031201,0
406031301,0

I need a batch that will add a 0 to the 6th place if the number is only 8
digits, and if it is 9 digits, leave it alone. Any help would be
appreciated for I have several thousands of these to do.

Daniel
- - - - - - - - - - begin screen capture Win2000 - - - - - - - - - -
c:\cmd>type c:\temp\MyNumbers.txt
40603604,0
40603605,0
406031201,0
406031301,0

c:\cmd>demo\FixMyNumbers
406030604,0
406030605,0
406031201,0
406031301,0

c:\cmd>rlist demo\FixMyNumbers.cmd
=====begin c:\cmd\demo\FixMyNumbers.cmd ====================
1. @echo off
2. for /f "tokens=*" %%a in (c:\temp\MyNumbers.txt) do call :fix %%a
3. goto :EOF
4. :fix
5. set input=%*
6. if "%input:~8,1%" EQU "," set input=%input:~0,5%0%input:~5%
7. echo %input%
=====end c:\cmd\demo\FixMyNumbers.cmd ====================
- - - - - - - - - - end screen capture Win2000 - - - - - - - - - -
 
Daniel said:
I need a batch that will add a 0 to the 6th place if the number is only 8
digits, and if it is 9 digits, leave it alone. Any help would be

Try something like this. I'll leave you to figure out how to 'capture'
the output:-

@echo off & setlocal ENABLEEXTENSIONS
set in="yourfile"

for /f "delims=" %%a in ('more^<%in%') do (
set "code=%%a"
call :doit
)
goto :EOF

:doit
if "%code:~8,1%"=="," set code=%code:~0,5%0%code:~5,3%,0
echo/%code%
 
Back
Top