leop1212
asked on
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
when you merge two files i don' t see how you align lines by a.key2=b.key2 ?
If you are referring to my script, I use cmd line parameters..
$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)
[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
$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
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?
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?
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.
Open in new window