|
Answer» my ck.txt has (note there will be spaces after comma jothi, m john, n joseph, o jane,b my data.txt has jothi john joseph johny i have requirement like if first argument in the chk.txt file matches with argument in data.txt then write the second argument(m,n,o,etc by triing the spaces) of the chk.txt file to a file new.txt i.e i need OUTPUT as new1.txt having m n o for this i USED command in batch file as for /f %%i in (data.txt) do for /f " delims=, tokens=1,2 " %%j in (ck.txt) do if %%j==%%i set dat=%%k & set data=%dat: =% & echo %data% >> new1.txt but in the file new1.txt ECHO is on ECHO is on ECHO is on
Can anyone solve this
Regards Jothish
If I understood you right the following code should work. (No guarantue if it is buggy) ;-) I am WORKING with NT4, so I don't know how it behaves in other Windows VERSIONS.
@echo off setlocal cls del new1.txt
for /f %%i in (data.txt) do for /f " delims=, tokens=1,2 " %%j in (ck.txt) do call :sub1 %%i %%j %%k
endlocal goto :eof :sub1 set data=%1 set ck=%2 set k=%3 if %data% EQU %ck% (echo %k% >>new1.txt)
:eof
hope it helps ulihey it is working fine gurantee that it is bug FREE
|