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