2018-05-07 16:04:23 +02:00
|
|
|
#!/bin/sh
|
|
|
|
# Usage:
|
|
|
|
# $ bash merge-csv.sh [directory_with_csvs]
|
|
|
|
|
2019-07-03 01:17:46 +02:00
|
|
|
# $Id: merge-csv,v 1.4 2018/08/28 12:29:05 gilles Exp gilles $
|
2018-05-07 16:04:23 +02:00
|
|
|
|
|
|
|
# Merge all non-header lines into merged.csv
|
|
|
|
merge_pattern() {
|
|
|
|
pattern=${1:-rrrrrrrrrr}
|
2019-07-03 01:17:46 +02:00
|
|
|
> ${pattern}_merged.csv;
|
2018-05-07 16:04:23 +02:00
|
|
|
for fname in `ls -r *${pattern}-stats.csv`
|
|
|
|
do
|
|
|
|
test -f $fname || continue
|
2019-07-03 01:17:46 +02:00
|
|
|
echo "tail -n 2 $fname | head -1"
|
|
|
|
# last one is not accurate, the day is not finished.
|
|
|
|
tail -n 2 $fname | head -1 >> ${pattern}_merged.csv;
|
2018-05-07 16:04:23 +02:00
|
|
|
done
|
|
|
|
|
|
|
|
test -f ${pattern}_merged.csv || return
|
|
|
|
# Get the unique rows by column 1, 2
|
|
|
|
awk -F"," '!seen[$1, $2]++' ${pattern}_merged.csv > ${pattern}_merged2.csv
|
|
|
|
|
|
|
|
# Sort the final rows in alpha order - first by the first col., then by second col.
|
|
|
|
sort -k1,1 -k2,2 ${pattern}_merged2.csv > ${pattern}_merged3.csv
|
|
|
|
|
|
|
|
# Rename and cleanup output
|
|
|
|
# Commented out 'rm' commands just in case
|
|
|
|
#rm ${pattern}_merged.csv
|
|
|
|
#rm ${pattern}_merged2.csv
|
|
|
|
mv ${pattern}_merged3.csv imapsync_github_stats_${pattern}.csv
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
merge_pattern clone
|
|
|
|
merge_pattern referrer
|
|
|
|
merge_pattern traffic
|