Batch file to log cURL to .csv from terminal

Hopefully this is the right place to ask something like this as it’s somewhat related to working in the CLI…

I’m trying to write a simple batch file to run in the windows command prompt to write published event data to a .csv file. This works using the terminal event log cURL request provided on the particle console but my output to the .csv file is filled with excessive blank lines written in between publishes. Does anybody here have a similar project that could offer some insight how to format the output file to only collect my actual published data ignoring all of the other data particle spits out with the publish and not write hundreds of blank rows? Command prompt scripts are fairly new to me and I’ve searched high and low for an example to learn form with little progress.

I’m using this:
C:\Users\Me\Desktop> MycUrl >> datalog.csv

and it works as expected to append new data to the .csv correctly but the output looks like this:

event: My_Data
data: {“data”:"|15|24|-5.4|58|100|59|0|,ttl":60|published_at:“2020-05-05T03:13:26.450Z”|coreid:“xxxxxxxxxxxxxxxxxxxxxxxxxx”}

event: My_Data
data: {“data”:"|15|24|-5.4|58|100|59|0|,ttl":60|published_at:“2020-05-05T03:13:31.751Z”|coreid:“xxxxxxxxxxxxxxxxxxxxxxxxxx”}

I’d like it to be formatted as only my data like this:

This is obviously more of a windows question than particle directly but there’s a lot of smart folks here. Any guidance would be greatly appreciated.

If you want to parse and exctract the JSON string that comes with each event you’ll need some extra logic I’d not do with pure CMD or PowerShell (assuming Windows).
I’d go with a simple NodeJS program that subscribes to the events, parses, formats and writes your data.

If you only want to get rid of the blank lines but can accept the raw JSON string I only ran particle subscribe My_Data >> test.txt and didn’t get any unexpected blank lines.

1 Like

Thanks ScruffR,

I switched to using the subscribe function instead of the whole event and the data is usable without further parsing now. I’ll continue in this direction for this project.