0

I am trying to execute multiple Powershell commands via a batch script, however I am having trouble writing the output into the same CSV. This data is being pulled via API and I eventually will use a Python program to insert the data from the CSV into a SQL database. The issue is that the API only allows for one single metric be to be pulled at a time, whereas I need to append all of these metrics into a single CSV. Below is a sample script of two different commands, both of which export into their own CSV. If anyone can provide me with a way to combine the output of these into a single CSV I would greatly appreciate it as I am completely stuck.

python get_samplemetric1_daily.py --pkgs samplemetric1 --country_code 
samplecountry --date_from 2015-01-01 --date_to 2017-01-01 --format csv > MyFile1.csv

python get_samplemetric2_daily.py --pkgs samplemetric2 --country_code 
samplecountry --date_from 2015-01-01 --date_to 2017-01-01 --format csv >> MyFile1.csv

When I attempt to insert the command -skip 1 in the context below, the error I receive is:

 error: unrecognized arguments: select -skip 1

Below are the two ways I attempted to insert the select -skip 1 command:

python get_samplemetric2_daily.py select -skip 1 --pkgs samplemetric2 --country_code 
samplecountry --date_from 2015-01-01 --date_to 2017-01-01 --format csv >> MyFile1.csv

and

    python get_samplemetric2_daily.py --pkgs samplemetric2 --country_code 
samplecountry --date_from 2015-01-01 --date_to 2017-01-01 --format csv  select -skip 1 >> MyFile1.csv
ls101
  • 177
  • 5
  • 17
  • 1
    Can you use the append redirector? `>> myfile1.csv`? (i dont know python but that looks like you are running it from command?) – Matt Apr 04 '17 at 18:36
  • That is exactly what I needed. Thanks! – ls101 Apr 04 '17 at 19:18
  • hey Matt, one more quick question. How would I use the append redirector, but only append everything starting at row 2? – ls101 Apr 04 '17 at 19:38
  • 1
    In PowerShell: `select -skip 1`. – Ansgar Wiechers Apr 04 '17 at 20:51
  • Thanks for the response Ansgar, however I keep getting errors when trying to apply this in my powershell script. How would I apply it in the context above? **I will edit the question now to show what my current (working) script is. Thank you again. – ls101 Apr 04 '17 at 21:37
  • I am now redirecting the second command to MyFile1.csv. I just need the second command to skip the first line (I currently have a python loop that puts MyFile1.csv into a SQL database, skipping the first row). However if it is easier to apply select -skip 1 to both commands that is ok. – ls101 Apr 04 '17 at 21:39

0 Answers0