1, curriculum knowledge overview section
1) The Three Musketeers awk command Overview Introduction
2) The Three Musketeers awk command syntax structure principle
3) The Three Musketeers awk command of practical operation
· Query things
· replacement information
· exclude (inverted)
4) The Three Musketeers awk command advanced features [] array of
statistical analysis of data summation / accumulation operations (there is even one)
2, review curriculum knowledge Description
1) sed sed command syntax parameter 'conditional instructions' file information
parameters:
-n ----- canceled output mode
-i ------ actually edit the contents of a file
-r ---- identifying the extended regular
-e ----- identifying a plurality of operating conditions
command
P output mode ---
D ---- deletion
A ---- additional operations
I insert ----
S ---- replace operation
g ------ global Alternatively
R & lt ------
C -----
condition information
$
n-
n-, m
/ character /
\
3、三剑客awk命令概述部分
awk - pattern scanning and processing language
模式扫描(处理文件每一行信息)过程语言(一门脚本语言)
作用说明:
1)擅长对文件的列操作
2)擅长统计分析数据信息
4、三剑客awk命令执行原理
执行原理过程:
命令语法结构:awk 【参数】 ‘模式{动作信息}’ 文件信息 模式就是条件
5、三剑客awk 命令操作练习
环境准备
几列 默认的是空格为间隔
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、显示Xiaoyu的姓氏和ID号码
a)根据条件找出相应的行
awk /Xiaoyu/
awk.txt 选取行
b)输出相应列信息
awk '/Xiaoyu/{print $1" "$3}' awk.txt
Zhang 390320151
awk '/Xiaoyu/{print $1,$3}' awk.txt
Zhang 390320151
说明:$n~/xxx/ 指定查找某人的捐款
- 姓氏是zhang的人,显示他的第二次捐款金额及他的名字
解题步骤一: 根据条件找出相应行awk '$1~/Zhang/' awk.txt
Zhang Dandan 41117397 :250:100:175 Zhang Xiaoyu 390320151 :155:90:201
[root@oldboy69 oldboy 10:43:46]# awk -F ":" '{print $2,$3}' test08.txt|column -t
linux 69
linux 66
python 20
dba 01
说明: 利用-F指定列分隔符
[root@oldboy69 oldboy 10:49:50]# awk -F ":|;|@" '{print $2,$3}' test08.txt|column -t
linux 69
linux 66
python 20
dba 01
[root@oldboy69 oldboy 10:49:52]# awk -F "[:;@]" '{print $2,$3}' test08.txt|column -t
linux 69
linux 66
python 20
dba 01
说明: 利用-F指定列分隔符, 结合正则可以识别多个分隔符号
[root@oldboy69 oldboy 10:54:13]# awk -F "[ :@]+" '{print $2,$3}' test08.txt|column -t
linux 69
linux 66
python 20
dba 01
说明: 利用-F指定列分隔符. 可以使用[ :@]+将多个连续分隔符看成一个整体
-
显示所有以41开头的ID号码的人的全名和ID号码
解题步骤一: 根据条件找出相应行
awk '$3~/^41/' awk.txt解题步骤二: 输出相应列信息 # awk '$3~/^41/{print $1,$2,$3}' awk.txt Zhang Dandan 41117397 Liu Bingbing 41117483
- 显示所有以5或者0结尾id显示出来, 并显示人的名字和ID号码
不要以0或5结尾的
-
显示Xiaoyu的捐款,每个时都有以$开头, 如$110$220$330
awk替换信息方法
gsub(/替换的信息/,"要替换成什么",$n替换的第几列信息)awk '$2~/Xiaoyu/{gsub(/:/,"$",$4);print $4}' awk.txt
$155$90$201
6、三剑客awk命令高级用法
01、awk模式概念
普通模式:利用正则进行匹配/利用行号进行匹配/利用字符进行匹配
特殊模式:
·BEGIN 在处理文件之前先做的事情(准备工作)
a、将awk作为计算机使用
b、进行变量的设定
内置变量:
NR:表示行号
NF:表示字段信息(列)
FS: 表示分隔符字段信息
·END 在处理文件之后要做的事情(后续工作)
输出结果 信息
Ps:在系统中有时引号需要窃入式使用时,不能使用相同的
‘‘’’----双单引号不对
““””----双 双引号不对
“‘’” ----单双引号使用
c)输出相应列信息
将数据对齐
7, awk Lessons Learned
1) awk command syntax: awk Parameters 'mode (2) {operation}'} information file
2) Use awk:
Arguments: -F
-v
· motion information: print gsub operation ( cumulative summation)
good extraction column information
3) awk advanced part of the knowledge:
A) mode concept: special mode Normal mode
b) built-in variables: NR NF FS
:( preview next week to explain the content)
1, user permissions knowledge
2, timed task knowledge
3, disk partition management knowledge arrays
day off a comprehensive exam
Networking basics
Integrated Architecture website deployment