Thursday, October 28, 2010

Command to calculate number of rows in a file

Sometimes there are so many files and you want to count number of rows in each file the a command or a shell script is handy to get it done otherwise its almost impossible to count number of rows in file. Following are some ways to calculate this.

  1. wc -l *.csv (This command will count rows per csv file)
  2. #!/bin/bash
    rows=0;
    for f in `*.CSV`;
      do
        let rows+=`wc $f | awk '{print $1}'`

      done

    echo "Total rows=$rows"
I hope this small tutorial is of help to you guys.

No comments:

Post a Comment