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

后端 未结 13 721
情深已故
情深已故 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:46

    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.

提交回复
热议问题