当前位置:网站首页>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
边栏推荐
- Melodic + Realsense D435i 配置及错误问题解决
- Sunfeng, general manager of Yixun: the company has completed the share reform and is preparing for IPO
- PHP website design ideas
- Mongodb source code deployment and configuration
- MySQL table operation
- Thymeleaf setting disabled
- Idea settings ignore file configuration when submitting SVN
- Okaleido ecological core equity Oka, all in fusion mining mode
- Doris learning notes integration with other systems
- Idea error failed to determine a suitable driver class
猜你喜欢

D2. Chopping Carrots (Hard Version) (每日一题)

Comprehensive sorting and summary of maskrcnn code structure process of target detection and segmentation

Maya modeling exercise

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

English语法_不定代词 - other / another

疫情之下,生物医药行业或将迎来突破性发展

DVWA practice - brute force cracking

Interpretation of featdepth self-monitoring model for monocular depth estimation (Part 2) -- use of openmmlab framework

Why do China Construction and China Railway need this certificate? What is the reason?

51单片机学习笔记(1)
随机推荐
telnet远程登录aaa模式详解【华为eNSP】
PHP website design ideas
Save the image with gaussdb (for redis), and the recommended business can easily reduce the cost by 60%
牛客多校 E G J L
English grammar_ Indefinite pronoun - other / other
Summary of some problems about left value and right value [easy to understand]
为什么中建、中铁都需要这本证书?究竟是什么原因?
Oka pass rights and interests analysis is the best choice to participate in okaleido ecological construction
Easy entry natural language processing series 12 hidden Markov models
Flask SSTI injection learning
Throwing OutOfMemoryError “Could not allocate JNI Env“
BIO、NIO、AIO示例
Educational Codeforces Round 132 (Rated for Div. 2) C,D+AC自动机
Jqgrid select all cancel single line click cancel event
Problems and extensions of the monocular depth estimation model featdepth in practice
关于ROS2安装connext RMW的进度条卡在13%问题的解决办法
What you must know about data engineering in mlops
~4.2 CCF 2021-12-1 sequence query
The main function of component procurement system, digital procurement helps component enterprises develop rapidly
Huawei ENSP router static route (the next hop address of the default route)