Linux Command Learning 1 (awk, grep), awkgrep

Source: Internet
Author: User

Linux Command Learning 1 (awk, grep), awkgrep

1. Write AWK internal code (for better understanding)

BEGIN{size=0}{    if($5>4096){    size=size+$5;    printf("%-10i%s\n",$5,$9)}}END{print "size is",size/1024/1024}

2. Remove the carriage return and add other parts.

ls -l|awk 'BEGIN{size=0}{if($5>4096){size=size+$5;printf("%-10i%s\n",$5,$9)}}END{print "size is",size/1024/1024}'

Objective: To view the files larger than 4 kb in the current directory and add the files to obtain the total size.

3. view files in the current directory larger than 4 kb

ls -l|awk 'if($5>4096){printf("%-10i%s\n",$5,$9)}'

4. AWK common parameter-F (which indicates what is a separator)

grep 'nologin$' /etc/passwd|awk -F ':' '{print $1}'

Objective: To view nologin users

Grep displays the rows ending with nologin. AWK queries the information of the first column separated ":".

5. Common grep Parameters

-C: print the number of rows that meet the requirements (and count the number of rows that meet the requirements)
-I: case insensitive
-N: print the row that meets the requirements and display the row number.
-V: Print B on the contrary (and do not contain the content that meets the requirements)

grep -c 'nologin$' /etc/passwd

Objective: to query the number of nologin users

grep -v 'nologin$' /etc/passwd

Purpose: To query non-nologin users

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.