0

I have this short config.txt with 2 lines

Preamp: 11dB
Include: example.txt

Is there a way for batch to find number before dB and replace it with either 1 higher or 1 lower?

8
  • There are too many ways to count, really. What have you tried? Just out of curiosity, this is for Equalizer APO, right? Commented Jun 16, 2016 at 12:06
  • yep it is, tried exchanging string but dont really know how to take number as variable, i dont really use batch much Commented Jun 16, 2016 at 12:13
  • You read the line and strip away everything but the number. Easy way to do it would be to use the second token of the line, 11dB, and set the d as the end of line character. for /f "usebackq eol=d tokens=2" %%I in ("%configfile%") do if not defined dB set /a dB=%%I + 1 or - 1 Commented Jun 16, 2016 at 12:33
  • I see the idea, but it tries changing db itself not number before, if i understand corectly it tries to makes something like "11 I+1", please advise Commented Jun 16, 2016 at 12:50
  • There are lots of existing questions (with answers) here regarding replacing text in files via batch. You've apparently not made any effort to search here first, or you would have located one of those many questions and would have at least an effort to do this yourself in your post. Please do that research now, and come back when you can edit your post to include that effort and ask a specific question related to it. Good luck. Commented Jun 16, 2016 at 12:50

1 Answer 1

1
@ECHO OFF 
REM read two lines:
<config.txt (
  set /p "line1="
  set /p "line2="
)
REM isolate the number:
set "line1=%line1:* =%"
set "line1=%line1:dB=%"
REM add one:
set /a line1+=1
REM write new file:
>config.txt (
  echo Preamp: %line1%dB
  echo %line2%
)
Sign up to request clarification or add additional context in comments.

1 Comment

That's why I am on this site. You learn a new trick all the time. That redirection thing is awesome. +1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.