2016-11-21 00:27:04 +01:00
|
|
|
#!/bin/bash
|
|
|
|
# Script zur Zählung von belegten Werten in TSV-Dateien
|
|
|
|
# Stand: 20.11.2016
|
2016-12-19 00:24:58 +01:00
|
|
|
# Nutzung: ./count-tsv.sh file.tsv
|
2016-11-21 00:27:04 +01:00
|
|
|
|
|
|
|
# Abfrage der Dateinamen
|
|
|
|
if [ -z "$1" ]
|
|
|
|
then
|
|
|
|
echo "Bitte Dateinamen angeben!"
|
2016-12-19 00:24:58 +01:00
|
|
|
echo "Beispiel: ./count-tsv.sh file.tsv"
|
2016-11-21 00:27:04 +01:00
|
|
|
exit
|
|
|
|
else
|
|
|
|
echo "Folgende Dateien werden untersucht:"
|
|
|
|
files=($*)
|
2016-12-19 00:24:58 +01:00
|
|
|
printf '%s\n' "${files[@]}"
|
2016-11-21 00:27:04 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Schleife für mehrere Dateien
|
|
|
|
for file in "${files[@]}"; do
|
|
|
|
|
2016-12-19 00:24:58 +01:00
|
|
|
echo ""
|
|
|
|
echo $file
|
|
|
|
echo ""
|
|
|
|
printf '%-30s\t%-10s\t%-10s \n' "SPALTENNAME" "ZEILEN" "ZEILEN-MIT-␟"
|
|
|
|
|
2016-11-21 00:27:04 +01:00
|
|
|
# Spaltennamen erfassen
|
2016-12-19 00:24:58 +01:00
|
|
|
readarray columns < <(head -q -n1 ${file} | tr '\t' '\n' | cat)
|
2016-11-21 00:27:04 +01:00
|
|
|
|
|
|
|
# Belegte Zellen in Spalten zählen und ausgeben
|
|
|
|
number=1
|
|
|
|
for column in "${columns[@]}"; do
|
2016-12-19 00:24:58 +01:00
|
|
|
printf '%-30s\t%-10d\t%-10d \n' ${column} $(cut -d$'\t' -f ${number} ${file} | grep -v '^$' | wc -l) $(cut -d$'\t' -f ${number} ${file} | grep '␟' | wc -l)
|
2016-11-21 00:27:04 +01:00
|
|
|
number=$(($number+1))
|
|
|
|
done
|
|
|
|
done
|