How do you replace a line in a text file containing a specific value (batch) -


the point of batch script take user entered account number , replace line in text file containing account number "xxxxxxxxxxxxxxxxxxxxx". how go doing that? right displaying account information of account number.

set /p acct_code=enter account code: echo. setlocal enabledelayedexpansion set flag=0 /f "tokens=1-3 delims=," %%r in (accounts.txt) ( if %%r==!acct_code! ( cls echo account information echo *******************  echo account code : %%r echo account name : %%s echo account balance : %%t set flag=1 ) ) if !flag!==0 echo account not found, please try again... echo. pause cls 

you missed code write line again (to new file):

... /f "tokens=1-3 delims=," %%r in (accounts.txt) (   if %%r==!acct_code! (     cls     echo account information     echo *******************      echo account code : %%r     echo account name : %%s     echo account balance : %%t     echo(%r,%%s,%%t >>accounts.new     set flag=1   ) else (     echo xxxxxxxxxxxxxxxxxxxxx>>accounts.new   ) ) echo move /y accounts.new accounts.txt ... 

(note: rename new file (overwrite original file), remove echo before move)


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -