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

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

    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
    

提交回复
热议问题