win7 - batch - 更改文本文件中的数字/字符串

时间:2016-06-16 11:41:59

标签: string windows batch-file

我有这条简短的config.txt有2行

Preamp: 11dB
Include: example.txt

批处理是否有办法在dB之前找到数字,并将其替换为1 higher1 lower

1 个答案:

答案 0 :(得分: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%
)