In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
1. Overview of course knowledge.
1) Overview of the three Musketeers awk command
2) three Musketeers awk command execution principle syntax structure
3) practical practice of the three Musketeers' awk command
Inquire about things
Replacement information
Exclude (reverse)
4) three Musketeers awk command advanced functions [array]
Statistical analysis data information summation operation / accumulation operation (one by one)
2. Review of course knowledge
1) sed command syntax format sed parameter 'conditional directive' file information
Parameters:
-n-cancel output mode
-I-actually edit the contents of the file
-r-identify extended regularity
-e-identify multiple conditional operations
Instruction
P-output mode
D-delete operation
A-additional operation
I-insert operation
S-replace operation
G-Global replacement
R-
C-
Conditional information
$
N
N,m
/ character /
\
3. Overview of the three Musketeers awk command
Awk-pattern scanning and processing language
Pattern scanning (processing each line of information in a file) process language (a scripting language)
Function description:
1) be good at column operations on files
2) be good at statistical analysis of data and information
4. The execution principle of the three Musketeers awk command.
Perform the principle process:
Command syntax structure: awk [parameter] 'mode {action information}' file information mode is the condition
5. Three Musketeers awk command operation exercise
Environmental preparation
The default for several columns is the space interval.
Zhang Dandan 41117397: 250:100:175
Zhang Xiaoyu 390320151: 155:90:201
Meng Feixue 80042789: 250:60:50
Wu Waiwai 70271111: 250:80:75
Liu Bingbing 41117483: 250:100:175
Wang Xiaoai 3515064655: 50:95:135
Zi Gege 1986787350: 250:168:200
Li Youjiu 918391635: 175:75:300
Lao Nanhai 918391635: 250:100:175
1. Display the last name and ID number of Xiaoyu
A) find the corresponding lines according to the conditions
Awk / Xiaoyu/ awk.txt select row
B) output the corresponding column information
Awk'/ Xiaoyu/ {print $1 "" $3} 'awk.txt Zhang 390320151awk' / Xiaoyu/ {print $1 recording 3} 'awk.txt Zhang 390320151
Note: $n~/xxx/ specifies to find someone's donation
A person whose surname is zhang shows the amount of his second donation and his first name
Step 1: find out the corresponding line according to the conditions: awk'$1 hammer Zhangmax 'awk.txtZhang Dandan 41117397: 250:100:175Zhang Xiaoyu 390320151: 155
[root@oldboy69 oldboy 10:43:46] # awk-F ":"'{print $2 test08.txt 3} 'test08.txt | column-t
Linux 69
Linux 66
Python 20
Dba 01
Description: use-F to specify column delimiter
[root@oldboy69 oldboy 10:49:50] # awk-F ": |; | @"'{print $2 column 3} 'test08.txt | column-t
Linux 69
Linux 66
Python 20
Dba 01
[root@oldboy69 oldboy 10:49:52] # awk-F "[:; @]"'{print $2 column 3} 'test08.txt | column-t
Linux 69
Linux 66
Python 20
Dba 01
Description: use-F to specify column delimiters, combined with rules can identify multiple delimiters
[root@oldboy69 oldboy 10:54:13] # awk-F "[: @] +'{print $2 column 3} 'test08.txt | column-t linux 69 linux 66 python 20 dba 01 description: use-F to specify column delimiter. You can use [: @] + to treat multiple consecutive delimiters as a whole
Displays the full name and ID number of all people with ID numbers starting with 41
Step 1: find out the corresponding lines according to the conditions
Awk'$3march / ^ 41Universe 'awk.txt
Step 2: output the corresponding column information # awk'$3million / ^ 41 / {print $1, awk.txtZhang Dandan 41117397Liu Bingbing 41117483 shows all id displays ending with 5 or 0, and displays the person's name and ID number.
Do not end with 0 or 5
Show Xiaoyu donations, each time starting with $, such as $110,220,330.
Awk replacement information method
Gsub (/ replaced information /, "what to replace with", column number of information replaced by $n)
Awk'$2~/Xiaoyu/ {gsub (/: /, "$", $4); print $4} 'awk.txt
$155 $90 $201
6. Advanced usage of the three Musketeers awk command
01. Awk schema concept
Normal pattern: using regular matching / line number matching / character matching
Special mode:
What BEGIN does before processing the file (preparation)
A. Use awk as a computer
B, set the variable
Built-in variables:
NR: indicates the line number
NF: represents field information (column)
FS: represents delimiter field information
What END will do after processing the file (follow-up work)
Output result information
Ps: sometimes when quotation marks need to be used stealthily in the system, the same
''-double single quotation marks are incorrect
"double quotation marks are incorrect.
"'"-use single and double quotation marks
C) output the corresponding column information
Align data
7. Summary of awk course
1) awk command syntax format: awk [parameters] 'mode (2) {actions}'} file information
2) how to use awk:
Parameter:-F
-v
Action information: print gsub operation (cumulative summation)
Good at taking out the information of the column
3) Advanced knowledge of awk:
A) the concept of patterns: special models, general models
B) built-in variable: NR NF FS
Preview: (what will be explained next week)
1. Knowledge of user rights
2. Timed task knowledge
3. Disk management knowledge array partition
Take a day off for a comprehensive exam
Basic knowledge of network
Integrated architecture website deployment
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.