Count rows in Windows command prompt

Source: Internet
Author: User

using the built-in tools find statistics cmd.exe the number of rows output is very convenient!

When working in a command-line environment, it is sometimes useful to be able to count the number of rows of output from different tools. Many Unix/linux operating systems contain WC tools with many feature options, and Windows does not have the same built-in alternatives, but the Windows command prompt (Cmd.exe) natively supports some of the same features.

This article will tell you how we can use the FIND tool to count the number of rows in Cmd.exe. Tool find, some like grep on Unix, has been in existence since MS-DOS and is easy to use.

Let's say we have a Windows server and want to see how many active TCP sessions are currently in the table. This can be done using the netstat command, and the pipeline connects to find to locate an established session.

Netstat-ano | find/i "Estab"

The output of this line of command may be hundreds of rows full of command prompt windows, and we may only care about the number of sessions. By adding A/ C switch option after this command, we can get the number of open TCP sessions.

We still use the filter rule of the previous command (find the line containing the established state by finding the string "Estab") but with/C, which will only show the number of matching rows.

Another example below is the number of DNS records that are viewed locally cached.

The/C option can also be used to count all lines of a command output. For example, we want to know the number of groupings in directory services (Active directory). Connecting to find/v ""/C through a pipe, we can count all rows (i.e., non-blank lines) that do not match (/v ) An empty string (""). If you have used the Unix tool WC, this is equivalent to wc-l .

Another example is the Event Viewer command-line tool, wevtutil , which outputs a large number of log data rows. If you just want to know the number of different logs in a modern Windows system, we can stream the file names of hundreds of log files to find/v ""/C.

The last example is the assumption that there is a log file or similar file with a total of thousands of lines of content. We want to quickly know the number of data rows that contain a particular phrase.

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

Count rows in Windows command prompt

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: info-contact@alibabacloud.com 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.