-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_csv_columns.sh
More file actions
executable file
·35 lines (26 loc) · 998 Bytes
/
check_csv_columns.sh
File metadata and controls
executable file
·35 lines (26 loc) · 998 Bytes
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
#!/bin/bash
# Script to check CSV files for consistent column counts
CSV_DIR="/home/smalley/akadata-amiga-io/platforms/amiga/registers"
echo "Checking CSV files for consistent column counts..."
for csvfile in "$CSV_DIR"/*.csv; do
echo "Checking: $csvfile"
# Count columns in header (first line)
header_cols=$(head -n 1 "$csvfile" | tr ',' '\n' | wc -l)
echo " Header has $header_cols columns"
# Check each line for consistent column count
line_num=1
while IFS= read -r line; do
line_cols=$(echo "$line" | tr ',' '\n' | wc -l)
if [ "$line_cols" -ne "$header_cols" ]; then
echo " ERROR: Line $line_num has $line_cols columns (expected $header_cols)"
echo " Content: $line"
fi
((line_num++))
# Limit to first 100 lines to avoid long processing
if [ "$line_num" -gt 100 ]; then
break
fi
done < "$csvfile"
echo ""
done
echo "Check complete."