![awk练习题-v参数 awk练习题-v参数](https://image.shishitao.com:8440/aHR0cHM6Ly9ia3FzaW1nLmlrYWZhbi5jb20vdXBsb2FkL2NoYXRncHQtcy5wbmc%2FIQ%3D%3D.png?!?w=700&webp=1)
[xxxx.com]
a=123
bsas=sa2
asd=a12
ip=ip123
[ooo.com]
asd12=1223
ip=ip123
xas=123
[xxoo.cn]
asas=123s
ip=xs12
213=2d
2131d=213
条件参数: ip=?结果: 输出上面[]那一行
示例:查ip=xs12 输出
[xxoo.cn]
查ip=ip123:输出
[xxxx.com]
[ooo.com]
说明:每个[]行后面有一些信息,不固定行数。ip=? 这一个参数也不固定在后面[]第几行,但是一定存在。
awk -F= -vip="ip123" '/^\[/{a=$0}$2==ip{print a}' file
#########################
先将[]的内容匹配存储a,利用匹配原则
再将需求指出,利用条件判断,输出满足条件的的存储a