当前位置:网站首页>awk从入门到入土(23)awk内置变量ARGC、ARGC--命令行参数传递
awk从入门到入土(23)awk内置变量ARGC、ARGC--命令行参数传递
2022-07-25 14:28:00 【奇妙之二进制】
awk可以通过-v var=value的形式向awk脚本传递变量,除了这种方式之外,还可以直接在awk命令行上直接传递,如:
$ echo a | gawk 'BEGIN{ for(i = 0 ; i < ARGC; i++) print ARGV[i]}' xx
gawk
xx
awk提供了两个内置变量,ARGC表示命令行参数个数,ARGV是个存放命令行参数的数组,大小由ARGC指示。
注意,名字区分大小写。
可是,我们发现,如果增加一条非BEGIN语句,则会出错:
$ echo a | gawk 'BEGIN{ for(i = 0 ; i < ARGC; i++) print ARGV[i]} {}' xx
gawk
xx
gawk: cmd. line:1: fatal: cannot open file `xx' for reading: No such file or directory
awk似乎将后面的参数作为待处理文件的名字了。
真是原因是awk会依次读取ARGV数组的元素,将其作为待处理文件的名字进行处理。
幸运的是,我们可以通过修改ARGV数组来避免这个问题。
直接减小ARGC的值,会导致awk不会读取尾部的一些文件。此外,增减ARGC的值,都不会影响ARGV数组,仅仅只是影响awk读取文件的数量。
# ARGC的值是3,修改成2,不会读取b.txt
awk 'BEGIN{ARGC=2}{print}' a.txt b.txt
边栏推荐
- Why do China Construction and China Railway need this certificate? What is the reason?
- DVWA practice - brute force cracking
- 元器件采购系统的主要功能,数字化采购助力元器件企业飞速发展
- pt100测温电路图(ad590典型的测温电路)
- Feiwo technology IPO meeting: annual revenue of 1.13 billion Hunan Cultural Tourism and Yuanli investment are shareholders
- Initial flask and simple application
- C language and SQL Server database technology
- What you must know about data engineering in mlops
- Detailed explanation of Telnet remote login AAA mode [Huawei ENSP]
- Products on Apple's official website can save 600 yuan by buying iPhone 13 Pro max at a discount
猜你喜欢

What you must know about data engineering in mlops

MySQL table operation

如何让一套代码完美适配各种屏幕?

Idea settings ignore file configuration when submitting SVN

Alibaba cloud installs mysql5.7

English grammar_ Indefinite pronoun - other / other

用GaussDB(for Redis)存画像,推荐业务轻松降本60%

Interpretation of featdepth self-monitoring model for monocular depth estimation (Part I) -- paper understanding and core source code analysis

~4.2 CCF 2021-12-1 sequence query

Mysql表的操作
随机推荐
牛客多校 E G J L
基于redis的keys、scan删除ttl为-1的key
Idea settings ignore file configuration when submitting SVN
SSM framework integration, simple case
Sunfeng, general manager of Yixun: the company has completed the share reform and is preparing for IPO
Realize a family security and environmental monitoring system (II)
51单片机学习笔记(2)
金鱼哥RHCA回忆录:CL210管理存储--管理共享文件系统
Nuc980 set up SSH xshell connection
Keys and scan based on redis delete keys with TTL -1
物理量与单位符号的书写标准
Famous handwritten note taking software recruit CTO · coordinate Shenzhen
D2. Chopping Carrots (Hard Version) (每日一题)
OverTheWire-Bandit
The concept and operation rules of calculus of variations
知名手写笔记软件 招 CTO·坐标深圳
~5 new solution of CCF 2021-12-2 sequence query
bond0脚本
Idea regular expression replacement (idea regular search)
Introducing mlops interpretation (I)