awk 脚本同时解析多个文件
ARGC The number of command line arguments (does not include
options to gawk, or the program source). 命令行参数的个数
ARGIND The index in ARGV of the current file being processed. 命令行中文件序号
ARGV Array of command line arguments. The array is indexed
from 0 to ARGC - 1. Dynamically changing the contents
of ARGV can control the files used for data. 命令行参数数组
参考来源:https://blog.csdn.net/liuzhoulong/article/details/7879300
直接替代码(脚本名为parallel.awk):
BEGIN{
print "HELLO!"
for(i=;i<ARGC;i++)
{
print ARGV[i];
}
}
{
if(ARGIND==)
{
print "1_"$;
}
else if(ARGIND ==)
{
print "2_"$;
}
else if(ARGIND==)
{
print "3_"$;
}
}
END{ }
解析文件:
1.txt
a
b
c
2.txt
a
b
c
3.txt
a
b
c
执行awk脚本: awk -f parallel.awk 1.txt 2.txt 3.txt
结果如下:
HELLO!
awk
.txt
.txt
.txt
1_1 a
1_2 b
1_3 c
2_4 a
2_5 b
2_6 c
3_7 a
3_8 b
3_9 c
关于NR,FNR:当前文件的行号FNR;总的行号是NR。
斜杠互相替换:
gsub(/\\/,"/",str);
gsub("/","\\",info);
解析为sql语句的时候,经常会遇到单引号的问题:
printf("select * from acct where log_datetime between '\''2018-10-15 00:00:00'\'' and '\''2018-10-15 23:59:59'\'' and name in (%s);",str);
最新文章
- css面包屑导航编号
- ANT的安装
- CSS应用心得
- yum标准化安装nginx最新版
- CSS3新添加的属性
- 在c#中使用log4net
- Eclipse全屏及插件下载
- jmeter压测SSL加密网站
- URAL 1180. Stone Game (博弈 + 规律)
- 基于Office 365 无代码工作流分析-需求基本分析!
- 201521123115《Java程序设计》第14周学习总结
- Android Studio 2.3 instant run与miui冲突问题的解决
- Linux的文本处理工具浅谈-awk sed grep
- Python random() 函数
- 记自己在spring中使用redis遇到的两个坑
- Emote木马分析
- selector 模块
- go基本操作
- [转] YUM 源优先级插件:Yum Priorities
- IEEEXtreme 10.0 - Checkers Challenge