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

后端 未结 13 701
情深已故
情深已故 2020-12-23 03:09

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 03:51

    If your file is big but you are certain that the number of columns remains the same for each row (and you have no heading) use:

    head -n 1 FILE | awk '{print NF}'
    

    to find the number of columns, where FILE is your file name.

    To find the number of lines 'wc -l FILE' will work.

提交回复
热议问题