![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| Guest | Count the number of Columns/rows in a CSV file.... Hi, I am trying to count the number of columns and rows in a CSV file and place the values into integer variables so they can be manipulated later. I thought maybe using the measure-object command to count the number of lines would be helpful but cant cast this explicitly as an integer (so cant edit the count values returned). I am not sure how to return the value of the number of columns, is there a way to count the number of 'noteproperty' member types using import-csv 'file' | gm ? Any help into this will be greatly appreciated. |
My System Specs![]() |
| | #2 (permalink) |
| Guest | Re: Count the number of Columns/rows in a CSV file.... # assign csv data to a variable (optional) $csv = import-csv data.csv # column count ($csv | get-member -type NoteProperty).count # ...or (import-csv data.csv | get-member -type NoteProperty).count # row count # enclose the object in # array notation '@()' # ensuring the count of scalar objects @($csv).count # ...or @(import-csv data.csv).count -- Kiron |
My System Specs![]() |
| | #3 (permalink) |
| Guest | Re: Count the number of Columns/rows in a CSV file.... Excellent, thanks for the help! "Kiron" wrote: Quote: > # assign csv data to a variable (optional) > $csv = import-csv data.csv > > # column count > ($csv | get-member -type NoteProperty).count > > # ...or > > (import-csv data.csv | get-member -type NoteProperty).count > > # row count > # enclose the object in > # array notation '@()' > # ensuring the count of scalar objects > > @($csv).count > > # ...or > > @(import-csv data.csv).count > > > -- > Kiron > |
My System Specs![]() |
| | #4 (permalink) |
| Guest | Re: Count the number of Columns/rows in a CSV file.... Quote: > I am trying to count the number > of columns and rows in a CSV file @" 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 nLogParser.exe "SELECT COUNT(*) FROM withFieldNames.csv" ` -i:csv -headerRow n -stats ff -q nBoth return 3 and LogParser.exe "SELECT COUNT(*) FROM withFieldNames.csv" ` -i:csv -headerRow ff -stats ff -q nreturns 4 Oh and one can do this with other file types too! Just another way! |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Count number of times a box is ticked in Access 2003 | Microsoft Office | |||
| How do I filter rows in one csv file matching a value in another | PowerShell | |||
| add an empty line to txt file every two rows. | PowerShell | |||
| Re: how to count number of certain char within string | PowerShell | |||
| count number of files | PowerShell | |||