0

I would like to replace 01 day string to 25 in my duepayment.txt file (approx. 2500 lines). For example, change 08012014 to 08252014 (mmddyyyy) without changing any other text containing "01".

original duepayment.txt file;

001-01      NSW       08012014    
001-02      VIC       01012015  

result desired.txt

001-01      NSW       08252014    
001-02      VIC       01252015  
Mark
  • 3,609
  • 1
  • 22
  • 33
LPlate
  • 3
  • 1
  • are you sure you stuck with the DOS and can't even use power shell? – sha Apr 03 '14 at 02:57
  • i dont know how to use power shell. – LPlate Apr 03 '14 at 03:04
  • i got DOS scripts, but it changes all tests are containing "01" including year..2014 became 2254 :( – LPlate Apr 03 '14 at 03:06
  • if "%~1"=="" findstr "^::" "%~f0"&GOTO:EOF for /f "tokens=1,* delims=]" %%A in ('"type %3|find /n /v """') do ( set "line=%%B" if defined line ( call set "line=echo.%%line:%~1=%~2%%" for /f "delims=" %%X in ('"echo."%%line%%""') do %%~X ) ELSE echo. – LPlate Apr 03 '14 at 03:06
  • I presume you are on Windows. So you really want a Windows batch script, not a DOS batch script. There are significant differences. – dbenham Apr 03 '14 at 11:46

1 Answers1

0

The solution is quite simple if you use a tool that supports regular expression search and replace.

A good option is my REPL.BAT utility - a hybrid JScript/batch script that performs regular expression search and replace on stdin and writes the result to stdout. It is pure script that will run natively on any modern Windows machine from XP forward. Full documentation is embedded within the script.

The regular expression below looks for lines that end with whitespace, 2 digits, 01, 4 digits, and then optional whitespaces. It preserves the values within the parentheses (represented by $1 and $2), and substitutes 25 for the 01.

type duepayment.txt | repl "(\s\d\d)01(\d{4}\s*)$" "$125$2" >desired.txt
Community
  • 1
  • 1
dbenham
  • 127,446
  • 28
  • 251
  • 390