0

質問-1) 私は 2 つのファイルを持っています

file1 が持っている

abc=123
acd=234
helloa=455
hellob=768
adb=234

file2 が持っている

abc=123
acd=564
helloa=2343
hellob=123
adb=685

私は文字列helloaを知っていますが、その右側に何があるかわかりません。私がしたいことは、file1のhellob右側の値をfile2の値に変更することです。helloahellob

私が試したこと

set a=0
for /f "delims=" %%i in ('^<file1 findstr /n "^"') do (
set "line=%%i"
setlocal enabledelayedexpansion
set "line=!line:*:=!"
if not "!line!"=="!line:helloa=!" set a=!line!
endlocal
)

次にfile1の行を置き換えますが、行はaにコピーされず、aはまだ0です

question-2) file1 の拡張子

line1
line2
hello1
hello2

ファイル2

line1
line2
hello1
hello2
hello3

ここで、file1 のすべての行を削除し、それらをfile2 の行にhello置き換えたいhello

4

1 に答える 1

0

これでQ1は解決

@echo off

for /f "tokens=1,* delims==" %%a in ('find "helloa" ^< file2.txt') do set helloa=%%b
for /f "tokens=1,* delims==" %%a in ('find "hellob" ^< file2.txt') do set hellob=%%b

for /f "delims=" %%a in (file1.txt) do (
for /f "delims==" %%b in ("%%a") do (
if "%%b"=="helloa" (
>>file.tmp echo helloa=%helloa%
) else if "%%b"=="hellob" (
>>file.tmp echo hellob=%hellob%
) else (
>>file.tmp echo(%%a
)
)
)
move file.tmp file1.txt
pause
于 2013-05-05T15:03:00.020 に答える