The way the Linux shell counts the number of rows __linux

Source: Internet
Author: User

This article refers to the example on the http://www.docin.com/p-56167731.html

1. Statistics of the number of rows of a file can be made with the following command:

Grep-c "" Xxx.txt

Or

Grep-n "" Xxx.txt | Wc-l

___________________________

Ps:

Use the Grep-n "" Xxx.txt to display line numbers for xxx.txt content.

Like what

Grep-n ""/etc/passwd

Output results:
1:root:x:0:0:root:/root:/bin/bash
2:daemon:x:1:1:daemon:/usr/sbin:/bin/sh
3:bin:x:2:2:bin:/bin:/bin/sh
4:sys:x:3:3:sys:/dev:/bin/sh
5:sync:x:4:65534:sync:/bin:/bin/sync
6:games:x:5:60:games:/usr/games:/bin/sh
7:man:x:6:12:man:/var/cache/man:/bin/sh
8:lp:x:7:7:lp:/var/spool/lpd:/bin/sh
9:mail:x:8:8:mail:/var/mail:/bin/sh
10:news:x:9:9:news:/var/spool/news:/bin/sh

....

____________________________

Or

Cat Xxx.txt | Wc-l

____________________________

Ps:

You can also output text content with line numbers by using the Cat-n Xxx.txt method

And it's better than the grep-n effect.

Like Cat-n/etc/passwd.
1 Root:x:0:0:root:/root:/bin/bash
2 daemon:x:1:1:daemon:/usr/sbin:/bin/sh
3 bin:x:2:2:bin:/bin:/bin/sh
4 sys:x:3:3:sys:/dev:/bin/sh
5 Sync:x:4:65534:sync:/bin:/bin/sync
6 games:x:5:60:games:/usr/games:/bin/sh
7 man:x:6:12:man:/var/cache/man:/bin/sh
8 lp:x:7:7:lp:/var/spool/lpd:/bin/sh
9 mail:x:8:8:mail:/var/mail:/bin/sh
Ten news:x:9:9:news:/var/spool/news:/bin/sh

...

In addition, a simpler command with a line-number output file is NL, which is equivalent to Cat-n

____________________________

2. Statistics command execution results of the number of rows

find/etc/-type F | Number of files under Wc-l #统计/etc/

find/etc/-type f-name "*iscsi*" | Wc-l #统计文件名中带有iscsi的文件数

find/etc/-type f-exec grep "Mdadm" {}/; | Wc-l #统计/etc/Directory, number of rows with mdadm content

find/etc/-type f-name "*iscsi*" | awk ' End{print NR} ' #统计文件名中带有iscsi的文件数

find/etc/-type f-exec grep "Mdadm" {}/; | awk ' End{print NR} ' #统计/etc directory, number of rows with mdadm content

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.