|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Generates "CSV_REPORTS.md" containing a reference to all CSV cypher query reports in this directory and its subdirectories. |
| 4 | + |
| 5 | +# Note: This script was generated by Chat-GPT after some messages back and forth: |
| 6 | +# https://chat.openai.com/share/0bd3cde7-32d0-460d-830c-79b7d00a2492 |
| 7 | + |
| 8 | +# Output Markdown file name |
| 9 | +output_file="CSV_REPORTS.md" |
| 10 | + |
| 11 | +# Function to count rows in a CSV file |
| 12 | +count_rows() { |
| 13 | + wc -l < "$1" |
| 14 | +} |
| 15 | + |
| 16 | +# Function to extract the source query name from CSV header |
| 17 | +get_source_query() { |
| 18 | + header=$(head -n 1 "$1") |
| 19 | + source_query=$(echo "$header" | sed -n 's/.*Source Cypher File: \(.*\)"/\1/p') |
| 20 | + echo "$source_query" |
| 21 | +} |
| 22 | + |
| 23 | +# Create the Markdown header |
| 24 | +{ |
| 25 | + echo "# CSV Cypher Query Reports Reference" |
| 26 | + echo "" |
| 27 | + echo "This document serves as a reference for all CSV Cypher query reports in the current directory and its subdirectories. It provides a table listing each file, its corresponding analysis, the row count and the source query. This file was generated with the script [generateCsvReportsReference](./../scripts/documentation/generateCsvReportsReference.sh)." |
| 28 | + echo "" |
| 29 | + |
| 30 | + # Create the Markdown table header |
| 31 | + echo "| CSV File | Analysis | Number of Rows | Source Query |" |
| 32 | + echo "| -------- | -------- | -------------- | ------------ |" |
| 33 | +} > "$output_file" |
| 34 | + |
| 35 | +# Find and process CSV files |
| 36 | +find . -type f -name "*.csv" | while IFS= read -r csv_file; do |
| 37 | + num_rows=$(count_rows "$csv_file") |
| 38 | + source_query=$(get_source_query "$csv_file") |
| 39 | + |
| 40 | + # Get the main directory name |
| 41 | + main_dir=$(dirname "$csv_file" | cut -d '/' -f 2) |
| 42 | + |
| 43 | + # Get the base name of the file |
| 44 | + base_name=$(basename "$csv_file") |
| 45 | + |
| 46 | + # Escape special characters for Markdown |
| 47 | + csv_link=$(echo "$csv_file" | sed 's/\[/\\[/g; s/\]/\\]/g') |
| 48 | + |
| 49 | + # Create a link to the source query |
| 50 | + source_query_link="./../cypher/$source_query" |
| 51 | + |
| 52 | + # Append a new row to the Markdown table |
| 53 | + echo "| [$base_name]($csv_link) | $main_dir | $num_rows | [$source_query]($source_query_link) |" >> "$output_file" |
| 54 | +done |
| 55 | + |
| 56 | +echo "CSV table and header generated in $output_file" |
0 commit comments