CSV File:
No Headers
8=Fix1.1<SOH>9=70<SOH>35=AE<SOH>10=237 ----This entire message is FIXData value
8=Fix1.1<SOH>9=71<SOH>35=AE<SOH>10=238
8=Fix1.1<SOH>9=72<SOH>35=AE<SOH>10=239
8=Fix1.1<SOH>9=73<SOH>35=AE<SOH>10=240
Code Snippet of how I get the data into a CSV file from querying MS DB.
cnxn = pyodbc.connect('DRIVER={ODBC Driver 17 for SQL Server};SERVER=server;DATABASE=abc;UID=user;PWD=password')
sql = """select FIXData from table WHERE MessageTimestamp BETWEEN '2021-09-20 07:00:00' AND '2021-09-20 07:01:00';"""
rows = cursor.execute(sql)
with open(r'HOME/sqlresults.csv', 'w', newline='') as csvfile:
writer = csv.writer(csvfile)
# writer.writerow([x[0] for x in cursor.description]) --- dont want headers
for row in rows:
writer.writerow(row)
Issue:
- As can be seen from the CSV file, the entire FIX message is squished into 1 cell (thinking Excel here).
- The FIX message is separated by , and basically I want to separate the tags into separate cells.
Desired Output:
- CSV file format (ideally separated by ';') so that when I open the csv in excel, the tag values will be in there own cell and not compressed in one.
8=Fix1.1;9=70;35=AE;10=237
8=Fix1.1;9=71;35=AE;10=238
8=Fix1.1;9=72;35=AE;10=239
8=Fix1.1;9=73;35=AE;10=240
Bonus Desired Output:
- This is optional, but if can be done within the above would be helpful.
- Remove the first part of tag
CSV File
Fix1.1;70;AE;237
Fix1.1;71;AE;238
Fix1.1;72;AE;239
Fix1.1;73;AE;240
Note:
- Please note I cannot use third party modules (Pandas dataframe not to be used etc)