How to count lines fast?
File.ReadLines was introduced in .NET 4.0 var count = File.ReadLines(file).Count(); works in 4 seconds, the same time as the first code snippet
File.ReadLines was introduced in .NET 4.0 var count = File.ReadLines(file).Count(); works in 4 seconds, the same time as the first code snippet
The following query helps you to get the count cat FILE_NAME | wc -l
In pure bash: (no awk) a=($(wc file.txt)) lines=${a[0]} words=${a[1]} chars=${a[2]} This works by using bash’s arrays. a=(1 2 3) creates an array with elements 1, 2 and 3. We can then access separate elements with the ${a[indice]} syntax. Alternative: (based on gonvaled solution) read lines words chars <<< $(wc x) Or in sh: a=$(wc file.txt) … Read more
An Example Using Your Own Data You can avoid having your filename embedded in the NUMOFLINES variable by using redirection from JAVA_TAGS_FILE, rather than passing the filename as an argument to wc. For example: NUMOFLINES=$(wc -l < “$JAVA_TAGS_FILE”) Explanation: Use Pipes or Redirection to Avoid Filenames in Output The wc utility will not print the … Read more
First you do not need to use cat to count lines. This is an antipattern called Useless Use of Cat (UUoC). To count lines in files in the current directory, use wc: wc -l * Then the find command recurses the sub-directories: find . -name “*.c” -exec wc -l {} \; . is the name … Read more
Most simple answer ever: wc < filename
Try this way: wc -l < file.txt