-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerateCsvReportReference.sh
More file actions
executable file
·62 lines (47 loc) · 2.3 KB
/
generateCsvReportReference.sh
File metadata and controls
executable file
·62 lines (47 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env bash
# Generates "CSV_REPORTS.md" containing a reference to all CSV cypher query reports in this directory and its subdirectories.
# Note: This script was generated by Chat-GPT after some messages back and forth:
# https://chat.openai.com/share/0bd3cde7-32d0-460d-830c-79b7d00a2492
# Fail on any error ("-e" = exit on first error, "-o pipefail" exist on errors within piped commands)
set -o errexit -o pipefail
# Output Markdown file name
markdown_file="CSV_REPORTS.md"
# Function to count rows in a CSV file
count_rows() {
wc -l < "$1"
}
# Function to extract the source query name from CSV header
get_source_query() {
header=$(head -n 1 "$1")
source_query=$(echo "$header" | sed -n 's/.*Source Cypher File: \(.*\)"/\1/p')
echo "$source_query"
}
echo "generateCsvReportReference: Generating ${markdown_file}..."
# Create the Markdown header
{
echo "# CSV Cypher Query Result Reports Reference"
echo ""
echo "This document lists all CSV Cypher query result reports found in the current directory and its subdirectories."
echo "Each entry in the table below includes the file name, the analysis type, the number of rows in the CSV, and the source Cypher query."
echo "This file was automatically generated using the [generateCsvReportReference](./../documentation/analysis-reports-reference/generateCsvReportReference.sh) script."
echo ""
# Create the Markdown table header
echo "| CSV File | Analysis | Number of Rows | Source Query |"
echo "| -------- | -------- | -------------- | ------------ |"
} > "$markdown_file"
# Find and process CSV files
find . -type f -name "*.csv" | sort | while IFS= read -r csv_file; do
num_rows=$(count_rows "$csv_file")
source_query=$(get_source_query "$csv_file")
# Get the main directory name
main_dir=$(dirname "$csv_file" | cut -d '/' -f 3)
# Get the base name of the file
base_name=$(basename "$csv_file")
# Escape special characters for Markdown
csv_link=$(echo "$csv_file" | sed 's/\[/\\[/g; s/\]/\\]/g')
# Create a link to the source query
source_query_link="./../cypher/$source_query"
# Append a new row to the Markdown table
echo "| [$base_name]($csv_link) | $main_dir | $num_rows | [$source_query]($source_query_link) |" >> "$markdown_file"
done
echo "generateCsvReportReference: Successfully generated ${markdown_file}."