Hi, I have file .txt file that contains date=04-FB-2011
How do I create a script that will prompt for a new date and replace the old one.
Jari
If your file looks like this: one
two
date=04-FB-2011
four
five
six
:: ==========================================
::
:: newdate.bat Tue 08-02-2011 18:38:01.42
@echo off > newfile & setLocal enableDELAYedeXpansionfor /f "tokens=1 delims=[]" %%a in ('find /n "date=" ^< my.txt') do (
set A=%%a
)set /p D=new date ? :
set N=
for /f "tokens=* delims= " %%a in (my.txt) do (
set /a N+=1
if !A! equ !N! (
echo.date=!D!
) else (
echo.%%a
)
) >> newfile
=====================================
Life is too important to be taken seriously.M2
Great script just what i needed! One thing I can't modify the scipt so that it would delete the old date row from the file.
In the newfile there will be two rows containing
date=04-FB-2011
date=09-FEB-2011/Jari
Mu Really great script. i would love to know the idea behind it..I mean how did you replaced just one line from the text file
Subhash Chandra.
www.s-chandra.co.cc
#2, Is that a question? #3, First loop finds the line number to be changed.
=====================================
Life is too important to be taken seriously.M2
Hi, I had in my.txt file some remarks in the beginning like:
# text
# text# text
date=04-MAR-2001
# textand this resulted in a newfile
# text
# text
# text
date=04-MAR-2001
date=22-mar-2011I just removed the empty row between the hash marks from my.txt and it works now ok.
I just didn’t realise immediately that the empty row would have such an effect on this scriptJari
oops, I didn't account for blank lines. Glad you made it go.
=====================================
Life is too important to be taken seriously.M2
Yes (14) | ![]() | |
No (14) | ![]() | |
I don't know (15) | ![]() |