Quote:
> I am trying to count the number
> of columns and rows in a CSV file
Perhaps Microsoft's Log Parser 2.2
@"
sphere,a.b.c,circle
cube,1.2.3,square
pyramid,apples.orange.pears,triangle
"@ | out-file noFieldNames.csv -encoding ascii
LogParser.exe -h: -i:csv -headerRow

ff noFieldNames.csv | `
select-object -last 11 | select-object -first 4
Returns:
Fields:
Filename (S) RowNumber (I)
Field1 (S) Field2 (S) Field3 (S)
@"
type,many parts,object
sphere,a.b.c,circle
cube,1.2.3,square
pyramid,apples.orange.pears,triangle
"@ | out-file withFieldNames.csv -encoding ascii
LogParser.exe -h: -i:csv -headerRow

n withFieldNames.csv | `
select-object -last 11 | select-object -first 4
Returns (with field names):
Fields:
Filename (S) RowNumber (I) type (S)
many parts (S) object (S)
And if you script it:
$a = LogParser.exe -h: -i:csv -headerRow

n withFieldNames.csv | `
select-object -last 11 | select-object -first 4
$b = [system.string]::Join(" ",$a)
($b.Split(")").Count -1) -2
returns
3
And now for the rows:
LogParser.exe "SELECT COUNT(*) FROM noFieldNames.csv" `
-i:csv -headerRow

ff -stats

ff -q

n
LogParser.exe "SELECT COUNT(*) FROM withFieldNames.csv" `
-i:csv -headerRow

n -stats

ff -q

n
Both return 3 and
LogParser.exe "SELECT COUNT(*) FROM withFieldNames.csv" `
-i:csv -headerRow

ff -stats

ff -q

n
returns 4
Oh and one can do this with other file types too!
Just another way!