Question : Append extra data to the right of common data between files


I have two files where in both, character positions 1 to 10 are the same, however in the second file I wish to copy everything from character position 101 to the end of line, into the first file where characters 1 to 10 are the same.

Is this possible in a dos environment?

Eg
File1:
0019283743  34 23 34 .....
2935782983  23 53 96 ....
0125892837  95 23 53 ....

File2:
0019283743  53 22 67 .... 23532.2035  235693
2935782983  64 75 74 .... 62837.2958  683023

Output:
0019283743  34 23 34 .... 23532.2035  235693
2935782983  23 53 96 .... 62837.2958  683023
0125892837  95 23 53 ....

As you can see while 1 to 10 are the same 11 to 100 differ. The .... is the rest of the data up to column 100.

These files can be very large, width and length, eg number of records will exceed 100000 records

Answer : Append extra data to the right of common data between files

It's not efficient, but this is an approach. Set the three vars at the start to your files.
The batch file is assuming the "key" value of the first 10 chars is unique, at least in file2. Else you will get only the last line found there for each key.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
@echo off
setlocal EnableDelayedExpansion
set file1=file1.txt
set file2=file2.txt
set out=output.txt

copy nul "%out%"
for /F "usebackq tokens=* delims=" %%A in ("%~file1%") do (
  set key=%%A
  set key=!key:~,10!
  set line=%%A
  for /F "tokens=* delims=" %%B in ('findstr /B /L /c:"!key!" "%~file2%"') do (
     set line=%%B
     set line=%%A!line:~100!
  )
  >> "%~out%" echo,!line!
)
Random Solutions  
 
programming4us programming4us