回答編集履歴
1
test
CHANGED
@@ -1,31 +1,36 @@
|
|
1
1
|
`enabledelayedexpansion`を使っている限り、`!`を使うのは無理です。
|
2
2
|
|
3
|
+
置換文字列を変数に置くのをあきらめて、
|
4
|
+
```CMD
|
5
|
+
set INPUT_FILE=test.txt
|
6
|
+
set OUTPUT_FILE=test2.txt
|
7
|
+
for /f "delims=" %%a in (%INPUT_FILE%) do call :FOO "%%~a"
|
8
|
+
exit /b
|
3
9
|
|
4
|
-
|
10
|
+
:FOO
|
11
|
+
set line=%~1
|
12
|
+
set line=%line:auth_password=Pass!012%
|
13
|
+
echo %line% >> %OUTPUT_FILE%
|
14
|
+
exit /b
|
15
|
+
```
|
16
|
+
ですね。
|
17
|
+
### 追記
|
5
|
-
|
18
|
+
「一旦は全角に変更しておき、後で半角に戻す」というのもありますね。
|
6
|
-
|
7
19
|
```CMD
|
20
|
+
set BEFORE_Pass=auth_password
|
21
|
+
set AFTER_Pass=Pass!012
|
8
22
|
|
9
23
|
set INPUT_FILE=test.txt
|
24
|
+
set OUTPUT_FILE=test2.txt
|
10
25
|
|
11
|
-
set
|
26
|
+
set AFTER_Pass=%AFTER_Pass:!=!%
|
12
|
-
|
13
|
-
for /f "delims=" %%a in (%INPUT_FILE%) do call :
|
27
|
+
for /f "delims=" %%a in (%INPUT_FILE%) do call :SUB "%%a"
|
14
|
-
|
15
28
|
exit /b
|
16
29
|
|
17
|
-
|
18
|
-
|
19
|
-
:
|
30
|
+
:SUB
|
20
|
-
|
21
31
|
set line=%~1
|
22
|
-
|
32
|
+
setlocal enabledelayedexpansion
|
23
|
-
set line=
|
33
|
+
set line=!line:%BEFORE_Pass%=%AFTER_Pass%!
|
24
|
-
|
34
|
+
endlocal&set line=%line%
|
25
|
-
echo %line%
|
35
|
+
echo %line:!=!%>>%OUTPUT_FILE%
|
26
|
-
|
27
|
-
exit /b
|
28
|
-
|
29
36
|
```
|
30
|
-
|
31
|
-
ですね。
|