I am trying to take the first row from multiple text files and add them to a new row in a CSV file, separated by columns. Currently, I am struggling with:
- Not overwriting previous data on the CSV file
- Skipping the header
- Excluding commas in strings like
Went From: 123 Address City, State
Currently, I have multiple text files each with information like date, time, etc. I wrote a bash script that takes each text files and pastes them into a CSV file:
paste -d "," col_Date col_Current_Time col_Weather col_From col_To col_Time_Elapsed > Database.csv
and I get:
2022-02-24,07:47:24,Went from: 2678, 20th Street, Ingleside Village, Tuscaloosa, Alabama 35401 United States, to: 2678 20th Street, Tuscaloosa, Alabama, 35401, United States, 1 s
and I want to get:
Date, Time, From, To, Time Elapsed
2022-02-24,07:47:24,Went from: 2678 20th Street Ingleside Village Tuscaloosa Alabama 35401 United States, to: 2678 20th Street Tuscaloosa Alabama 35401 United States, 1 s
Either I need to remove the commas in the string before, or somehow tell the CSV file to omit these specific commas in the From and To string. I write to each of the text files using this Python code:
with open(col_Date, 'w') as f3:
print(today, file=f3)
f3.close()
This is my second week of coding, so there is no such thing as over explaining to me. Let me know if you need anything else! Thank you!