Viewed 85k times. Should be take under 30 seconds to get the count of a 10 million line file. Improve this question. Add a comment. Active Oldest Votes. Echo theFile. Improve this answer. Marcucciboy2 3, 3 3 gold badges 16 16 silver badges 33 33 bronze badges. I would also point out that 8 means "For appending", which is why it immediately reads to the end of the file. Also, I would set the last argument to False, thus not creating the file if it does not exist, but instead allowing it to error out.
And use theFile. Line - 1 to return the number of lines that exist in the file, because theFile. Line returns the number of the line that you are about to write but which does not exist yet. What I was looking for. Thank you! ReadLine Loop wscript. CreateObject "Scripting. As an optimisation you can make the only thing in the loop filInput. ReadLine then when its done filInput. Good point! Will edit accordingly.
Actually, don't even need to read the line. Can just skip it! BTW I'm surprised you weren't the one to post a neat Regexp solution! Just being chivalrous Jean All answers were acceptable, doesn't matter which answer is accepted. You're already a chevalier in my sight : Someone chooses the most appropriate one for himself. Too large files ReadAll With oReg. Execute sData. Kul-Tigin Kul-Tigin You say it is faster Yes, I've tested to a sample large file. With the Regex, it tooks 8 secs only.
What do you mean by the comment in the commented-out line? There is no relation. Close WScript. Echo c,"lines". It works fine for one column in the txt file. Peter Hall Matt Matt 9 1 1 bronze badge. Horner Care to elaborate? At first glance, this looks legit to me. It's not VBScript and incrementing a counter if there is a. Line property is not right. Readline Loop msgbox strlinenumber t2.
Likewise, if you want to count the number of lines in single or multiple files, you can use different commands. You can use "-l" or "--line" option with wc command as follows:. You can see that wc also counts the blank line and print the number of lines along with the filename. Moreover, to display a number of lines from more than one file at the same time, you need to pass the filenames as arguments separated by space.
In another way, you can also make use of the cat command to redirect the file content to the wc command as input via pipe ' '. Though it will also count the number of lines in a file, here the use of cat seems redundant. Awk is a very powerful command-line utility for text processing.
If you already know awk , you can use it for several purposes including counting the number of lines in files. Hence, if you just want to use it to count the total number of lines in a file, you can remember the following command:. Sed is a also very useful tool for filtering and editing text. More than a text stream editor, you can also use sed for counting the number of lines in a file using the command:. So, combining it with the -n option, it counts the total number of lines in a file passed as an argument.
Using yet another useful pattern search command grep , you can get the total number of lines in a file using '-e' or '--regexp' and '-c' or '--count' options. You can use either of the regular expression.
Instead of directly getting the total no of lines, you can also print the file content and get the total number of lines by peeking at the last line number. For such purpose, nl is a simple command to print data with numbered lines. For large files, it does not seem like a suitable method to display all data in a terminal.
0コメント