|
Answer» Hi,
I'm WORKING in Win XP SP3.
I have a text file with bunch of topics and various number values after them, like: apples=4 grapes=5 bananas=3
I'd like to have a batch command that will open the file, find the line with the bananas and add a line before/above it, like: apples=4 grapes=5 pears=7 bananas=3
I've used the 'set' and 'if' well ENOUGH, but my results come out missing the line break, like: pears=7 bananas=3
I can't seem to get the added line break. Can someone help? Here is the code, I've tried
@echo off SETLOCAL=ENABLEDELAYEDEXPANSION set lf=^ rename fruitcount.txt fruitcount.tmp for /f %%a in (fruitcount.tmp) do ( set foo=%%a if !foo!==bananas=3 set foo=pears=7!lf!bananas=3 echo !foo! >> fruitcount.txt) del fruitcount.tmp
ThanksWhat does !foo! MEAN?!foo! is set to %%a above.
but %lf% is broken, and the actual task will DETERMINE the best way to go about it. It seems very unlikely that that is all you need to do.
This code will do as you ask (get the batch file CALLED `findrepl.bat` from - https://www.dropbox.com/s/rfdldmcb6vwi9xc/findrepl.bat and place it in the same folder as the batch file.)
Code: [Select]@echo off move fruitcount.txt fruitcount.tmp >nul type fruitcount.tmp |findrepl /o:1:2 >fruitcount.txt >>fruitcount.txt echo pears=7 type fruitcount.tmp |findrepl /o:3:3 >>fruitcount.txt pause
|