check 2 text files

November 9, 2010 at 11:55:17
Specs: Windows XP
sorry for my poor english but i will try to explane
I have 2 TEXT files for example BSIN11230091 and SUMD11230091
I want to make a BATCH to check if all the numbers after 4 first characters are the same then copy word from line X of the first file to line Y in the second file.

for example BSIN11230091 Contains 3 lines:
675348
8756
9083

SUMD11230091 Contains 6 lines:
a
b
c
d
e
f

Because the numbers after 4 first characters are the same i want to copy value 8756 to d
i know its look too complicate any way thanks for advanced


See More: check 2 text files

Report •


#1
November 10, 2010 at 05:07:47
The bat needs to know which linwa go where.


=====================================
Life is too important to be taken seriously.

M2


Report •

#2
November 10, 2010 at 05:32:59
last line from the first file BSIN11230091 to 4 line in the second file SUMD11230091 , but in the first file the lines are not always 3 ....sometimes they can be 20 or 5 but always i need the last line

Report •

#3
November 10, 2010 at 06:28:30
@echo off > newfile & setLocal enableDELAYedeXpansion

for /f "tokens=* delims= " %%a in (BSIN11230091) do (
set S=%%a
)

set N=

for /f "tokens=* delims= " %%a in (SUMD11230091) do (
set /a N+=1
if !N! equ 4 >> newfile echo.!S!
>> newfile echo.%%a
)


=====================================
Life is too important to be taken seriously.

M2


Report •

Related Solutions

#4
November 10, 2010 at 06:38:24
thanks for replay
can i use * like (BSIN*.txt )

Report •

#5
November 10, 2010 at 06:45:26
after i check your bat this is the output :
the last line was copy (thats good) to the 10 line instead of 4 line ??

Report •

#6
November 10, 2010 at 14:10:44
If you have a bunch of files post some names.


=====================================
Life is too important to be taken seriously.

M2


Report •

#7
November 10, 2010 at 23:14:51
they are created automaticly , they always start with BSIN and SUMD and after that alot of numbers....i need to fine the files with same name (after 4 char...)

Report •

#8
November 11, 2010 at 05:47:10
Will there be JUST TWO with the same names after BSIN and SUMD?


=====================================
Life is too important to be taken seriously.

M2


Report •

#9
November 11, 2010 at 05:52:50
yes just 2

Report •

#10
November 11, 2010 at 05:55:46
i need to find all the couples and do the copy.....between them
and thanks for your effort

Report •

#11
November 11, 2010 at 11:02:21
@echo off > newfile & setLocal enableDELAYedeXpansion

for /f "tokens=* delims= " %%b in ('dir /b BSIN*.') do (
set U=%%b
set U=!U:~4!

for /f "tokens=* delims= " %%a in (%%b) do (
set S=%%a
)
set N=

for /f "tokens=* delims= " %%a in (SUMD!U!) do (
set /a N+=1
if !N! equ 4 >> newfile echo.!S!
>> newfile echo.%%a
)
move /y newfile !U!
)
goto :eof


=====================================
Life is too important to be taken seriously.

M2


Report •

#12
November 11, 2010 at 22:58:06
i got : File Not Fount and an empty "newfile" ....
all files were under the batch and there are BSIN....files

Report •

#13
November 12, 2010 at 05:47:42
do dir/b

post result


=====================================
Life is too important to be taken seriously.

M2


Report •

#14
November 16, 2010 at 04:31:59
sorry for late response
after dir/b i got 12 files with BSIN... AND SUMD... and the batch file

Report •

#15
November 18, 2010 at 07:21:11
hi Mechanix2Go

i tried to run the command dir /b under CMD and its run OK
but when i try to run dir /b sumd*. under CMD i got an error File Not Found
so i read the Dir /? and the syntax not correct - can not run dir /b with *.* any ideas ?

thanks


Report •

#16
November 20, 2010 at 08:30:45
Mechanix2Go ,

when I change your BAT to ('dir BSIN*.txt /b') everything works fine so thanks alot for your help !

I want to ask about the line : if !N! equ 4 >> newfile echo.!S!
I change 4 to 10 its copy to 10 line (and thats OK) can I copy to line 10 after character 6 and not to the first character ?



Report •


Ask Question