Created
October 9, 2024 21:50
-
-
Save helsont/948daef025feb4389d98498386861711 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Create or empty the output file | |
> results.csv | |
# Define the header to add at the end | |
header="id,balance_id,account_id,currency,amount,balance_amount,type,related_entity_type,related_entity_id,related_entity_short_reference,status,reason,settles_at,created_at,updated_at,completed_at,action,cc_account_id" | |
# Find all .csv files in subdirectories with "missing" in their filename | |
find . -type f -name "*missing*.csv" | while read -r file; do | |
# Print the current file being processed | |
echo "Processing file: $file" | |
# Extract the directory name and get the account ID by removing the first 5 characters | |
dir_name=$(dirname "$file") | |
account_id=${dir_name:5} | |
# Remove the first line from each file, prepend the account ID to each row, and append the result to the output file | |
tail -n +2 "$file" | sed "s/^/${account_id},/" >> results.csv | |
# Add a newline after each file's content | |
echo "" >> results.csv | |
done | |
# Prepend the header to the results.csv file (using a temporary backup file for macOS compatibility) | |
sed -i '' "1s/^/$header\n/" results.csv | |
echo "Concatenation complete. Output saved to results.csv" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment