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

后端 未结 13 1119
深忆病人
深忆病人 2020-12-23 03:07

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.

13条回答
  •  囚心锁ツ
    2020-12-23 04:06

    A very simple way to count the columns of the first line in pure bash (no awk, perl, or other languages):

    read -r line < $input_file
    ncols=`echo $line | wc -w`
    

    This will work if your data are formatted appropriately.

提交回复
热议问题