Hazel and Bash script to combine individual csv files

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

I am pretty new to bash scripting but have watched several Lynda.com courses recently and figured out what I want to do in the terminal but now want to automate with Hazel. Likely could do in the terminal but I'm not that advanced. But willing to consider if people feel its best

I am receiving based customer data from a web form in a CSV file. The headers for the data are in column 1 and customer input in column 2. Each customer input is a separate CSV file

I want to automatically combine each CSV file so I can dashboard some of the data. Ultimately hope to display with the Charty App on IOS

In the terminal, I have used awk to extract the headers and place them in row 1 of a new file ill refer to as combined.csv

I have created another awk command to extract column 2 ( the customer data) and put it in a row separated by commas. The command I'm using is: awk 'BEGIN {FS=","}{RS="\r"}{ORS=","}{print $2}' file_name.csv >> combined.csv

**One issue I had is this places the new data on the same row as the headers which I can't figure out how to overcome.**** I can make my combined not have the headers if necessary but sure there is a way to fix.

Next, I decided to automate with Hazel. I have pointed it folder where the individual CSV files get placed. They have no tag so I want Hazel to identify the files with no tag and run an embedded bash script

awk 'BEGIN{FS=","}{RS="\r"}{ORS=","}{print $2}' $1 >>
filepath Combined.csv

In this reportedly the $1 is how you denote the current file Hazel is working on.

After running I would like Hazel to tag the file with "complete" so it won't be triggered again.

Hazel reports back an error saying it can't run the shell script.

Sorry for the long post. Any help would be appreciated.
Danaportenier
 
Posts: 1
Joined: Sat Jun 27, 2020 9:38 am

Have you tried the Hazel script outside of Hazel? Also, turn on debug mode (https://www.noodlesoft.com/kb/hazel-debug-mode/) and check the logs. Output from the script will appear there.
Mr_Noodle
Site Admin
 
Posts: 11255
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support