bat文件来替换特定的字符串 [英] Bat file to replace a specific String
问题描述
我要寻找一个批处理文件,改变了文件中的一行。
让我给你举个例子讲清楚。
我有一个文件test.properties
I am looking for a Bat Files that changes a line in a file. Let me give you an example to make it clear. I have a file test.properties
文件看起来是这样的:
hostname=<hostname>
port=0
rpcqueue=0
defaultlocale=en
defaulttimeout.normal=0
defaulttimeout.long=0
defaulttimeout.xlong=0
name=admin
passwd=406abbc8192eda42cc3261235959e23a8e223f6ab7f10d8cdf2e22fca
所以我想替换的背后passwd中的价值,但我的问题是我将要取代旧的,我不知道这个价值我只知道的值。
So I want to replace the value behind passwd but my problem is I don't know this value I only know the value with which i want to replace the old one.
这也应该是可以输入文件名,属性值(passwd)的并在命令行,这样我可以使用这个文件为其他文件到新的价值。
很抱歉,如果这个问题已经是地方,但我找不到它。
It should also be possible to enter the file name, the attribute value (passwd) and the new value over command line so that I could use this file for other files to. Sorry if this question is already somewhere but I couldn't find it.
我对蝙蝠的知识并不出众,我学习。
My knowledge about bat is not superior and I am learning.
谢谢!
推荐答案
启动此批处理文件是这样的:Mybatch新密码
Launch this batch file like this: Mybatch newpassword
这使用被称为一个辅助的批处理文件 repl.bat
- 从下载:的 https://www.dropbox.com/s/qidqwztmetbvklt/repl.bat
This uses a helper batch file called repl.bat
- download from: https://www.dropbox.com/s/qidqwztmetbvklt/repl.bat
将 repl.bat
在同一文件夹中的批处理文件或者是道路上的一个文件夹中。
Place repl.bat
in the same folder as the batch file or in a folder that is on the path.
@echo off
type "test.properties" |repl "(passwd=).*" "$1%1" >"newfile.properties"
这篇关于bat文件来替换特定的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!