当前位置:网站首页>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
边栏推荐
- 变分(Calculus of variations)的概念及运算规则
- H5页面input输入框弹起数字键盘,需要支持小数点
- MySQL table operation
- Doris学习笔记之与其他系统集成
- Famous handwritten note taking software recruit CTO · coordinate Shenzhen
- AI model risk assessment Part 1: motivation
- GameFramework制作游戏(二)制作UI界面
- pt100测温电路图(ad590典型的测温电路)
- ~4.1 sword finger offer 05. replace spaces
- Maya modeling exercise
猜你喜欢

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

Sunfeng, general manager of Yixun: the company has completed the share reform and is preparing for IPO

sqli-labs Basic Challenges Less1-10

GameFramework制作游戏(二)制作UI界面

阿里云安装MYSQL5.7

51单片机学习笔记(2)

【口才】谈判说服技巧及策略

filters获取data中的数据;filters使用data中的数据

Melodic + Realsense D435i 配置及错误问题解决

Interpretation of featdepth self-monitoring model for monocular depth estimation (Part 2) -- use of openmmlab framework
随机推荐
Apple failed to synchronize on its mobile terminal, and logged out. As a result, it could not log in again
Alibaba cloud installs mysql5.7
QObject source code analysis -d pointer and Q pointer
Idea settings ignore file configuration when submitting SVN
51单片机学习笔记(2)
That day, I installed a database for my sister... Just help her sort out another shortcut
C language and SQL Server database technology
Cologne new energy IPO was terminated: the advanced manufacturing and Zhanxin fund to be raised is the shareholder
[cartographer_ros] VIII: Official demo parameter configuration and effect
Flask SSTI injection learning
Application practice: Great integrator of the paddy classification model [paddlehub, finetune, prompt]
A small part is exposed on one or both sides of the swiper
变分(Calculus of variations)的概念及运算规则
苹果手机端同步不成功,退出登录,结果再也登录不了了
苹果手机端同步不成功,退出登录,结果再也登录不了
opencv视频跟踪「建议收藏」
机械制造业数字化新“引擎”供应链协同管理系统助力企业精细化管理迈上新台阶
Depth estimation self-monitoring model monodepth2 paper summary and source code analysis [theoretical part]
[eloquence] negotiation persuasion skills and Strategies
Typora cannot open the prompt to install a new version solution