Count columns for each file in a directory

From raju

Situation: The idea here is to count the number of columns for each file in a directory. Assume that the files are named foo.YYYYMMDD and the number of columns remains consistent across the file.

Solution:

    > cat count_columns.zsh
    #! /bin/env zsh
    
    # set -x
    
    cd /path/to/dir
    for file in foo.*
    do
        date=`echo $file | cut -c 5-12`
        fields=`head -q -n 1 $file |  tr "," "\n" | wc -l`
        printf "$date $fields\n"
    done
    

Sample run

    > ./count_columns.zsh > column_count.txt