-1

I began with an excel spreadsheet with a couple of columns (a Date of Birth, and a Last Name column). I extrapolated and used a batch file to modify just the date of birth column so that I now have a text file with the following (to be used in a SQL query):

BirthDateTime = '01/01/2017' AND Name LIKE '
BirthDateTime = '01/01/2016' AND Name LIKE '

I now want to take the second column (by creating a separate lastname.txt file) and concatonate it into the output file above line for line so that my last name file, which looks like:

SMITH
JONES

Will merge to a new output file that will look like:

(BirthDateTime = '01/01/2017' AND Name LIKE '%SMITH%') OR
(BirthDateTime = '01/01/2016' AND Name LIKE '%JONES%') OR

Unfortunately I'm a newbie on batch files and I just don't know where to start. I'm including the batch file I used to create the first part below.

Batch File:

@echo off
setLocal EnableDelayedExpansion
for /f "tokens=* delims= " %%a in (input.txt) do (
set /a N+=1
echo BirthDateTime = '%%a' AND Name LIKE '>>output.txt
)
mslhrt
  • 207
  • 1
  • 11
  • 1
    if this is a one-time-task, inserting a column manually in EXCEL is much easier. – Stephan Jun 06 '17 at 19:56
  • 1
    ... otherwise look [here](https://stackoverflow.com/a/43005887/2152082) how to read two files simultaniously. – Stephan Jun 06 '17 at 19:59

2 Answers2

0

Per @Stephan's comment I just set out to do this in Excel and used the following formula:

="(BirthDateTime = '"&A2&"' AND Name LIKE '%"&B2&"%') OR" which worked fine. Since I asked specifically about batch files I'm not sure it's appropriate for me to accept this as an answer. If somebody has some code, or if Stephan wants to post his link as an answer with some explanation into his code I will accept that, otherwise I will accept this as the answer in 2 days.

mslhrt
  • 207
  • 1
  • 11
0

Your question is a bit confusing. You show two textfiles, but your code seems to use some other files (Dates only). Anyway - I covered both possibilities; just use the right echo line.

To read and merge two files use a little trick (using two different methods to read a file):

@echo off
setlocal enabledelayedexpansion
<t2.txt (
  for /f "delims=" %%a in (t1.txt) do (
    set /p name=
    echo (%%a!name!'^) OR 
    REM echo (BirthDateTime = '%%a' AND Name LIKE '!name!'^) OR
  )
)>out.txt
type out.txt

The other trick is escaping the closing paranthese in the echo statement with a ^. If you don't, the parser takes it for the loop end, which will result in a crippled output and an errormessage "OR" is not recognized as a valid command ...

Stephan
  • 53,940
  • 10
  • 58
  • 91