How to get CSV dimensions from terminal
10,504
Try using awk
. It's best suited for well formatted csv file manipulations.
awk -F, 'END {printf "Number of Rows : %s\nNumber of Columns = %s\n", NR, NF}' Test.csv
-F,
specifies ,
as a field separator in csv file.
At the end of file traversal, NR
and NF
have values of number of rows and columns respectively
Another quick and dirty approach would be like
# Number of Rows
cat Test.csv | wc -l
# Number of Columns
head -1 Test.csv | sed 's/,/\t/g' | wc -w
Author by
user2763361
Updated on June 19, 2022Comments
-
user2763361 almost 2 years
Suppose I'm in a folder where
ls
returnsTest.csv
. What command do I enter to get the number of rows and columns ofTest.csv
(a standard comma separated file)?