Count rows in Windows cmd

Source: Internet
Author: User

The subject of this article comes from the translation of this foreign language article. There is a subtitle in the original text: "How to simply calculate the number of rows in CMD.exe with the Windows-brought find"

When we work in the command-line environment, it is sometimes useful to be able to calculate the number of rows that other tools output.

Many Unix/linux operating systems contain a tool called WC, which can be accepted without a few options,

There are no alternatives to this tool on Windows, but a Windows cmd prompt exists

A tool that can achieve almost any function.

In this passage, we'll see how to calculate the number of rows in cmd with find.

This tool is actually more like the Unix system grep, and it's already on the Windows operating system (in the DOS ERA),

Because this tool is available on all versions of versions of Windows, it's also easier to use (without having to install extra stuff).

For example, suppose you have a Windows Server and we want to know how many TCP sessions are currently active (active) and we can

With the netstat command, redirect the output of this command to the Find command to obtain a line with a status of established sessions, as follows:

Netstat-nao | find/i "Estab"

The output of the above command may be a lot of lines, perhaps we are only concerned about the number of sessions output,

As long as the command line above to fill in A/C command switch, you can get TCP in the active state of the sessions.

Looking at the above figure, we still use the same filter (that is, the "estab"), just add a/c option, the output is only the number of rows.

An additional example is the following, which shows the local cached DNS records.

The/C option can also be used to calculate all lines of the command output. For example, we may want to know the number of groups in the Active Directory.

The output from the previous command is directed to find/v ""/C (which means to look at all rows that do not contain a string "").

That is, calculate all rows!

By using the/V "", we will query to all non-empty rows, which is useful in cases where all strings in the output are very different.

If you use a WC on UNIX, the command above is equivalent to Wc-l.

In another example, the Event Logger command (wevtutil) outputs a number of rows, and if you just want to know the number of different logs on the current machine, simply redirect their output to

Find/v ""/C can.

One last example. There is a log file, there may be thousands of lines of similar content in the file, we want to quickly know the number of lines containing a keyword:

TYPE C:\Windows\Schedlgu.txt | find/i "Task failure"/C

The author concludes that there are some implementations of UNIX tools on Windows, but it is still useful to be able to use Windows-brought tools to accomplish certain tasks!

(Although tools like find have become a thing of the past!!!) )

Count rows in Windows cmd

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.