(Video materials in preparation)
ccnt : Counts the columns
Usage : ccnt [-f] [-v] <file1> <file2>...
ccnt -d <string>
Version : Thu Jan 15 16:51:13 JST 2015
Counts the number of columns in the text file passed as an argument or
from standard input.
Specify -d then the number of columns in text string <string> is counted.
$ a="X Y Z"
$ ccnt -d "$a"
3
When all rows have the same number of columns, that number is output.
$ cat data
a b c d
e f g h
$ ccnt data
4
If there are rows with different numbers of columns then the count
is output each time the number of columns changes.
$ cat data2
a b c
a b c
a b c
a b
a b c
$ ccnt data2
3
2
3
If you use the -v option then the row number is output whenever the
number of columns per row changes.
$ ccnt -v data2
1 3 <-- 3 columns from line 1
4 2 <-- 2 columns from line 4
5 3 <-- 3 columns from line 5
The -f option displays the input file name. If reading from standard
input then STDIN is displayed.
When used with the -v option, the input file name, line number and
number of columns are output in that order.
$ ccnt -f data2
data2 3
data2 2
data2 3
$ ccnt -f data data2
data 4
data2 3
data2 2
data2 3
$ cat data2 | ccnt -f data -
data 4
STDIN 3
STDIN 2
STDIN 3
$ ccnt -f -v data2
data2 1 3
data2 4 2
data2 5 3