mynote/linux/awk.md
2020-06-26 21:29:00 +08:00

38 lines
694 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 使用
[TOC]
参考
https://blog.csdn.net/daily886/article/details/85156557
## 基本规则
> awk [-F|-f|-v] BEGIN{} //{command1; command2} END{} file
常用形式:
> Awk -F '' '//{command}' file
- -F 'char': 确定分割符,默认分隔符是空格
- 常用变脸$0 $1 $2 ... 0代表正行1代表第一个切片
- 格式化输出 awk '/pattern/ {printf "echo 1st %s", $1}' file
- 匹配规则在//之间
## 常用
### awk 中执行shell命令
对于 某行数据 Version = "v1.2.3"
自动打标签并推送
> awk -F '"' '/Version/ {print $2;system("git tag "$2);system("git push origin "$2)}' onebd.go
注意在makefile中使用时$需用$$代替