How to get CSV sizes from terminal

Suppose I'm in a folder where ls returns Test.csv . What command do I enter to get the number of rows and columns Test.csv (standard comma-delimited file)?

+6
source share
1 answer

Try using awk . It is best suited for well formatted csv files .

 awk -F, 'END {printf "Number of Rows : %s\nNumber of Columns = %s\n", NR, NF}' Test.csv 

-F, indicates how the field separator is in the csv file.

At the end of the file traversal, NR and NF have values ​​for the 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 
+18
source

Source: https://habr.com/ru/post/957239/


All Articles