#!/usr/bin/env bash # Usage: ./add_csv_header.sh /path/to/trace_root set -euo pipefail if [[ $# -ne 1 ]]; then echo "Usage: $0 /path/to/trace_root" exit 1 fi TRACE_ROOT="$1" HEADER="experiment_name,chain,mean,std,min,max,count" if [[ ! -d "$TRACE_ROOT" ]]; then echo "Error: '$TRACE_ROOT' is not a directory." exit 1 fi # Find all results.csv files one level below the trace root find "$TRACE_ROOT" -mindepth 2 -maxdepth 2 -type f -name results.csv | while IFS= read -r csvfile; do # Insert header only if not already present first_line=$(head -n 1 "$csvfile") if [[ "$first_line" != "$HEADER" ]]; then echo "Adding header to $csvfile" sed -i "1i$HEADER" "$csvfile" else echo "Header already present in $csvfile, skipping." fi done