2013-05-05 51 views
0

問題-1)我有兩個文件從一個文件複製特定行到下一個

文件1已經

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

文件2已經

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

我知道該字符串helloahellob但我不知道什麼是在它的右側, 我想要做的是,更改右側的值在helloa和文件1的與file2的文件相同。

我曾嘗試

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 
) 

,然後替換文件1線,但線,永遠不會被複制到A,A仍然是0

問題-2)本 的文件1的延伸有

line1 
line2 
hello1 
hello2 

文件2

line1 
line2 
hello1 
hello2 
hello3 

在這裏,我想刪除所有hello線file1和與hello線的文件2

+0

回覆Q2:你想從文件1刪除了所有你好線,並已全部文件2中的hello行添加到file1的末尾 – foxidrive 2013-05-05 15:05:29

+0

'question-2)'對我來說沒有意義,用'hello1'替換'hello1'?你可以添加'hello3'並準備好。 – Endoro 2013-05-05 16:07:18

+0

我收集到OP在輸入例子時並不清晰,而file2與'hello'有不同的界限。 – foxidrive 2013-05-05 16:34:15

回答

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 
+0

謝謝,它的工作 – 2013-05-06 06:29:22

相關問題