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

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

    Following code will do the job and will allow you to specify field delimiter. This is especially useful for files containing more than 20k lines.

    awk 'BEGIN { 
      FS="|"; 
      min=10000; 
    }
    { 
      if( NF > max ) max = NF; 
      if( NF < min ) min = NF;
    } 
    END { 
      print "Max=" max; 
      print "Min=" min; 
    } ' myPipeDelimitedFile.dat
    

提交回复
热议问题