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

后端 未结 13 1224
深忆病人
深忆病人 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:07

    You can use bash. Note for very large files in terms of GB, use awk/wc. However it should still be manageable in performance for files with a few MB.

    declare -i count=0
    while read
    do
        ((count++))
    done < file    
    echo "line count: $count"
    

提交回复
热议问题