need help with batch file to edit two text files

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
jjlyon
Posts: 18
Joined: 11 Oct 2012 20:43

Re: need help with batch file to edit two text files

#16 Post by jjlyon » 09 Mar 2013 19:45

:lol: thank you so much for your help

jjlyon
Posts: 18
Joined: 11 Oct 2012 20:43

Re: need help with batch file to edit two text files

#17 Post by jjlyon » 21 Apr 2013 20:12

hi again, i have another problem. since this is a similar problem i thought i would post it under this topic.

i need a batch file that can combine the text in two different txt files into one. for example

name.txt
tony
josh
tom

Size.txt
Large
Small

and then combine the text into:

total.txt
tony Large
Josh Small
tom

as shown not all text will have something to combine with but it will still need to be copied over to the total.txt.
also if possible i would like there to be a space between each combine however no space to appear after non combined text or after combined text (if that is not possible that will be fine as long as there are no spaces anywhere but for the ones that ware originally in the text (such as 'tony smith' or 'very large')

any help would be greatly appreciated!

kind regards
Josh

Endoro
Posts: 244
Joined: 27 Mar 2013 01:29
Location: Bozen

Re: need help with batch file to edit two text files

#18 Post by Endoro » 22 Apr 2013 00:02

You should show more examples from your text files.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: need help with batch file to edit two text files

#19 Post by foxidrive » 22 Apr 2013 00:44

This will do as the OP asked - he can get back to us with more info if it fails.

! characters will cause an issue.

Code: Select all

@echo off
setlocal enabledelayedexpansion
<Size.txt (
for /f "delims=" %%a in (name.txt) do (
set "var="
set /p "var="
if defined var set "var= !var!"
>>total.txt echo %%a!var!
)
)

jjlyon
Posts: 18
Joined: 11 Oct 2012 20:43

Re: need help with batch file to edit two text files

#20 Post by jjlyon » 22 Apr 2013 09:16

:D that works great thanks foxidrive!
sorry Endoro, in future ill show more examples :)

Post Reply