Search code examples
bashrow

How do I count the number of rows and columns in a file using bash?


Say I have a large file with many rows and many columns. I'd like to find out how many rows and columns I have using bash.


Solution

  • Columns: awk '{print NF}' file | sort -nu | tail -n 1

    Use head -n 1 for lowest column count, tail -n 1 for highest column count.

    Rows: cat file | wc -l or wc -l < file for the UUOC crowd.