2025-01-02 10:46:09 +08:00

48 lines
963 B
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

awk
-F指定分隔符
变量
FS输入字段分隔符默认为空白字符功能相当于-F
自定义变量:-v var=value
语句块
BEGIN语句块
模式匹配的同游语句块
END语句块
工作过程
第一步执行BEGIN{action;...}语句块中的语句
第二步从文件或标准输入读取一行然后执行patternaction;...}语句块
第三步当读到末尾后执行END模块
常见action分类
print
,:分隔符
固定字符要用“”引用起来,而变量和数字不需要
printf
"FORMAT"
必须指定FORMAT且分别需要为后面每个item指定格式符
不会自动换行,需要显示给出换行控制符\n
%s显示字符串
%d显示十进制整数
%f显示为浮点数
%e显示科学计数法数值
%c显示字符的ascii码
%u显示无符号整数
算数,比较表达式
组合语句
ifwhile等
输入
控制语句
if
if else
while
do while
for
break
continue
exit