terça-feira, 23 de agosto de 2011

Contar linhas de um arquivo de texto ( txt )grande em windows

fonte : http://brett.batie.com/scripting/count-number-of-lines-in-a-file-using-dos/
Count number of lines in a file using DOS
Every once in a while I get on a computer and I need to count the number of lines in a file. My first instinct is to open my text editor (editplus) and hit ctrl+end to get to the bottom of the document. Then I can view the status bar which will tell me the line number. This works fine when I am on my computer but not when I am on another computer that does not have editplus installed.

My next option might be to open this file in notepad and do the exact same thing. This will work fine if the file is not to large. The problem is I often deal with very large files. I need a quicker way to produce the same results.

This is where DOS comes into play. I can use the following command and let DOS quickly tell me the number of lines in the file.

1
findstr /R /N "^" file.txt
This command will output every line with a line number in front of it but will still take a long time given a very large file. The solution to this is to take this command one step further.


Use este comando :
findstr /R /N "^" file.txt | find /C ":"
Now the output will only be the number of lines that are contained in the file.Again, this command could be taken a step further to tell you how many lines are in the file that contain a certain string.

1findstr /R /N "^.*certainString.*$" file.txt | find /c ":"
I'm sure there are many other great uses for find and findstr. If you have found one please post comment.

3 Comentários:

Às 21 de fevereiro de 2017 às 06:00 , Blogger Wesley Junio disse...

Great post!.
thank you.

 
Às 12 de janeiro de 2018 às 01:54 , Anonymous Anônimo disse...

Solved my little problem! Thanks a lot! greaT

 
Às 13 de fevereiro de 2020 às 11:10 , Blogger Derick disse...

Show!

 

Postar um comentário

Assinar Postar comentários [Atom]

<< Página inicial