how to merge to CSV files as a scheduled task

We have two CSV files exported from two different apps   on a weekly basis. We have to merge them and want to run it  as schedule task.
if i do it in SQL it will look like
Select a.key1, a.first, a. last, a.key2, b.number into c where a.key2=b.key2 and  a source1, b source2, c results

How can it be done with excel so we run it a a scheduled task? I all looking for a working syntax.
results.csv
source1.csv
source2.csv
leop1212Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Eric WoodfordSoftware Systems Specialist 3Commented:
You should be able to code something like this in powershell then trigger the script as a scheduled task.

For example, I coded this a while back to do something similar:
http://www.ericwoodford.com/2017/09/powershell-csv-join.html
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
abbas abdullaCommented:
Hi,

you can use this code
1. Change the paths to match your paths.
2.  Copy the code into new Notepad file
3.  Save the notepad file with  .bat extension.
4. schedule a task to open this file at the time or event you want the CSV files to be merged.


:: Merge CSV
@echo off
setlocal
set Source=C:\Users\Myuser\Downloads\Undo
set Dest=C:\Users\Myuser\Downloads\Undo\allbat.csv
::for /f "delims=" %%a in ('dir "%Source%\*.csv" /b /s') do (
::copy "%%a" "%Dest%"
copy "%Source%\*.csv" /b %Dest%

::)
pause

Open in new window

0
leop1212Author Commented:
when you merge two files i don' t see how you align lines by a.key2=b.key2 ?
0
Eric WoodfordSoftware Systems Specialist 3Commented:
If you are referring to my script, I use cmd line parameters..
 [parameter(Mandatory=$true,HelpMessage="Path and filename for source CSV 1")][ValidateScript({Test-Path $_ })][string]$csv1Name,
    [parameter(Mandatory=$true,HelpMessage="Propery from CSV1 to join files on.")][string]$csv1Property,
    [parameter(Mandatory=$true,HelpMessage="Path and filename for source CSV 2")][ValidateScript({Test-Path $_ })][string]$Csv2Name,
    [parameter(Mandatory=$true,HelpMessage="Propery from CSV2 to join files on.")][string]$csv2Property,
    [parameter(Mandatory=$true,HelpMessage="Path and Name for combined CSV file")][string]$JoinedCSV

Open in new window


$CSV1Property and $CSV2Property are the names of the keys $a.key and $b.key

In your sample CSV files, you have duplicate fields with different results. When I designed the script, I didn't have duplicate and different results (i.e. first name = first name in both CSV)

 .\CSVJoin.ps1 -csv1Name .\source1.csv -Csv2Name .\source2.csv -csv1Property key2 -csv2Property key2 -JoinedCSV .\myResults.csv

Open in new window

source files combine to make results.csv
0
Zeth LarssonCommented:
Do the source files have same name, and location every week?
What shall happend with old source files after merge to result?
Shall it be any role for the name of the latest result file?
Is all fields always in the same order as in your sample?
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SQL

From novice to tech pro — start learning today.