dataflow-analysis/csvfix.sh

29 lines
706 B
Bash
Executable file

#!/bin/bash
# Check if filename parameter is provided
if [ $# -eq 0 ]; then
echo "Usage: $0 <csv_filename>"
echo "Example: $0 data.csv"
exit 1
fi
CSV_FILE="$1"
# Check if file exists
if [ ! -f "$CSV_FILE" ]; then
echo "Error: File '$CSV_FILE' not found!"
exit 1
fi
echo "Processing file: $CSV_FILE"
echo "========================================"
# Count prefixes from first column
echo -e "\n=== Total number of unique prefixes ==="
cut -d',' -f1 "$CSV_FILE" | sort | uniq | wc -l
# Readable output format
echo "=== Formatted output ==="
echo "Prefix -> Count"
echo "---------------"
cut -d',' -f1 "$CSV_FILE" | sort | uniq -c | sort -nr | awk '{printf "%-20s -> %d\n", $2, $1}'