简体   繁体   中英

copy each line from 2 files to 1 file Windows batch

I have to files and both have the same amount of lines, and I need to copy each line of both files to a new file, but concatenated. So line 1 of both files need to be copied to line 1 of the new file, and even with additional text in that line. This is part of a bigger Windows batch (cmd.exe).

input file "date.txt":

150102
150103
150104
150105

input file "ID":

ID01
ID02
ID03
ID04

output file "Date_ID.txt" that I need:

150102 is the same as ID01
150103 is the same as ID02
150104 is the same as ID03
150105 is the same as ID04

Could anybody please help me with this? I tried things with /for and findstr but because it is looping I will get every combination of each date with each ID.

@echo off
setlocal enableDelayedExpansion
set "file1=path_to\date.txt"
set "file2=path_to\id.txt"
set "out=path_to\output.txt"

for /f %%N in ('type "%file1%"^|find /c /v ""') do set "cnt=%%N"
 >"%out%" 9<"%file1%" <"%file2%" (
   for /l %%N in (1 1 %cnt%) do (
    set "ln1="
     set "ln2="
    <&9 set /p "ln1="
    set /p "ln2="
    echo !ln1! is the same as !ln2!
  )
)
type "%out%"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM