Finding the minimum and maximum length of columns in a CSV file using shell script
<p>I have several CSV files with multiple columns, and I want to get the max length, min length of individual columns and diff (max -min) for each column in the same CSV file. Example:</p>

<p>File:</p>

<pre><code>abc 1234 4
bcd 23644 534
c 3232 6
</code></pre>

<p>Expected output:</p>

<pre><code>    abc 1234 4
    bcd 23644 534
    c 3232 6

Max Length 3 5 3
Min Length 1 4 1
Diff 2 1 2
</code></pre>

<p>The following script for computing the MAX column length is producing the expected output:</p>

<pre><code>awk -F, '
  { for (i=1;i&lt;=NF;i++)l[i]=((x=length($i))&gt;l[i]?x:l[i])}
  END {for(i=1;i&lt;=NF;i++) print "Column"i":",l[i]} '
</code></pre>

<p>but there is problem with MIN Length script:</p>

<pre><code>awk -F"," 'BEGIN {
    for (i=1;i&lt;=NF;i++) {
        cur = length($i)
        if ( (min == 0) || (cur &lt; min) ) {
            minlength = i
            min = cur
        }
    } ;
for (i=1;i&lt;=NF;i++) print $minlength}'
</code></pre>

<p>Any help would be greatly appreciated.</p>