Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
OK I am no programmer by any means but I get along OK most of the time. But I have an issue that is killing me. We receive a delimited text file that we need to update. One of the things I need to update on the file is a date. It is always proceeded by {20134{. The date in the text file is formatted m/yy I need to add the leading zero to it. Example:
111{20134{7/09
Needs to be:
111{20134{07/09This has been driving me nuts. Currently I am manually doing a find and replace for each month 1 -9 Is there any way to find these and change them all at once with a batch script? Can anyone help me?

Hi raremind
A few questions
1, How is the file delimited by comma's ect.
2, Is there any thing else on the date line.
3, Is there only one "/" in the file(s)
4, Is there only "{ " "}" on the date line

Thanks for your reply!
The file is delimited with {
The date line is formated as such 000000{000000{M/YY
Yes there is only one /
No every line uses the { delimiterThanks again your you help

Hi Micheal
Try this on some dummy files first to check that it works ok.
I including a check for a leading zero so files don't get modified twice,@echo off
SetLocal EnableDelayedExpansiondir /b Data*.txt>Files.txt
type nul>Tmp.txt
for /f "tokens=*" %%a in (Files.txt) do (
for /f "tokens=*" %%b in ('type "%%a"') do (
for /f "tokens=1-2 delims=/" %%c in ("%%b") do (
if "%%d"=="" (
echo %%b>>Tmp.txt
) else (
for /f "tokens=1-3 delims={" %%e in ("%%c") do (
set Day=%%g
set Zero=!Day:~,1!
if !Zero! NEQ 0 (
if %%g LSS 10 (set Day=0%%g)
echo %%e{%%f{!Day!/%%d >> Tmp.txt
) else (echo %%b>>Tmp.txt)
)
)
)
)
del "%%a"
ren Tmp.txt "%%a"
)del Files.txt

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |