更新属性从批处理文件文件通过跳过和打印注释和空行

问题描述 投票:1回答:1

我更新使用批处理文件的属性文件。我想知道如果我可以用跳绳和打印注释行和空行更新属性文件。我在财产文件中的一些功能按键都没有任何默认值。如果我保持=作为分隔符,然后一边做回声%%A=%%B,对于注释行我正在逐渐一行的末尾一个额外的=

下面是我的批处理文件:

echo off
 Set "Parametervalue=dev"
 Set "baseURLvalue=https://prodweb-dev.net/start"
 Set "urlvalue=/client/versions-6.0.1.xml"
 (for /f "usebackq tokens=1* delims==" %%A IN (
 myfile.properties
 ) do if "%%A" equ "Parameter" ( 
 echo Parameter=%Parametervalue%
 ) else if "%%A" equ "baseURL" (
 echo baseURL=%baseURLvalue%
 ) else if "%%A" equ "url" (
 echo url=%urlvalue%
 ) else (echo %%A=%%B)
 )>temp.properties

有望与注释行和空白行,如下原始文件更新的属性:

#configuration

#baseURL(mandatory)
baseURL=https://prodweb-dev.net/start

#descriptorurl(mandatory) 
#url=/client/versions-6.0.1.xml
url=/client/versions-6.0.1.xml

#Title (optional, new property, default value is "??") 
Title=

#ClientParameter  (optional, no default value) - parameters which will  be     passed to startup file and are accessible by the client application as     environment variable
Parameter=dev

#BackgroundImage (optional, default Image with Daimler logo) 
BackgroundImage=

下面是所获得的输出:

#configuration=
#baseURL(mandatory)=
baseURL=https://prodweb-dev.net/start
#descriptorurl(mandatory) =
#url=/client/versions-6.0.1.xml
url=/client/versions-6.0.1.xml
#Title (optional, new property, default value is "??") =
Title=
#ClientParameter  (optional, no default value) - parameters which will be     passed to startup file and are accessible by the client application as     environment variable=
Parameter=dev
#BackgroundImage (optional, default Image with Daimler logo) =
BackgroundImage=
batch-file cmd
1个回答
1
投票

这将替换所有文字需要离开其他线路不变。我将在我的电脑进行了更改一次,因为位置搜索是一项临时措施,因为我无法从我的手机进行测试。

@echo off
setlocal enabledelayedexpansion

set "iofile=myfile.properties"
set "_param=Parameter=dev"
set "_base=baseURLvalue=https://prodweb-dev.net/start"
set "_url=url=/client/versions-6.0.1.xml"

for /f "tokens=*" %%a in ('type "%iofile%" ^| find /v /n "" ^& break ^> "%iofile%"') do (
     set "str=%%a
     set "str=!str:*]=!"
     if "!str:~0,9!"=="Parameter" set "str=%_param%"
     if "!str:~0,7!"=="baseURL" set "str=%_base%"
     if "!str:~0,3!"=="url" set "str=%_url%"
     >>%iofile% echo(!str!
  )
© www.soinside.com 2019 - 2024. All rights reserved.