当前位置:网站首页>Awk from getting started to digging in (23) awk built-in variables argc, argc -- command line parameter transfer
Awk from getting started to digging in (23) awk built-in variables argc, argc -- command line parameter transfer
2022-07-25 14:30:00 【Wonderful binary】
awk Can pass -v var=value In the form of awk The script passes variables , Except in this way , You can also directly awk Pass directly on the command line , Such as :
$ echo a | gawk 'BEGIN{ for(i = 0 ; i < ARGC; i++) print ARGV[i]}' xx
gawk
xx
awk Two built-in variables are provided ,ARGC Indicates the number of command line parameters ,ARGV Is an array of command line parameters , Size by ARGC instructions .
Be careful , Names are case sensitive .
But , We found that , If you add a non BEGIN sentence , Then there will be mistakes :
$ 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 It seems that the following parameters are used as the name of the file to be processed .
The real reason is awk Will be read in turn ARGV Elements of array , Treat it as the name of the file to be processed .
Fortunately, , We can modify ARGV Array to avoid this problem .
Direct reduction ARGC Value , It can lead to awk Will not read some files at the end . Besides , Increase or decrease ARGC Value , Will not affect ARGV Array , Just influence awk Number of read files .
# ARGC The value of is 3, Modified into 2, Don't read b.txt
awk 'BEGIN{ARGC=2}{print}' a.txt b.txt
边栏推荐
- Feiwo technology IPO meeting: annual revenue of 1.13 billion Hunan Cultural Tourism and Yuanli investment are shareholders
- IDEA报错 Failed to determine a suitable driver class
- Realsense-Ros安装配置介绍与问题解决
- H5页面input输入框弹起数字键盘,需要支持小数点
- English grammar_ Indefinite pronoun - other / other
- 苹果手机端同步不成功,退出登录,结果再也登录不了
- 如何设计一个高并发系统?
- Mongodb source code deployment and configuration
- GameFramework制作游戏(二)制作UI界面
- IDEA设置提交SVN时忽略文件配置
猜你喜欢
随机推荐
基于redis的keys、scan删除ttl为-1的key
Realize a family security and environmental monitoring system (I)
Detailed explanation of nat/napt address translation (internal and external network communication) technology [Huawei ENSP]
From fish eye to look around to multi task King bombing -- a review of Valeo's classic articles on visual depth estimation (from fisheyedistancenet to omnidet) (Part I)
快速搭建Dobbo小Demo
~5 new solution of CCF 2021-12-2 sequence query
Doris学习笔记之与其他系统集成
awk从入门到入土(21)awk脚本调试
Development of uni app offline ID card identification plug-in based on paddleocr
Initial flask and simple application
MySQL table operation
sqli-labs Basic Challenges Less1-10
基于PaddleOCR开发uni-app离线身份证识别插件
Under the epidemic, the biomedical industry may usher in breakthrough development
Summary of some problems about left value and right value [easy to understand]
VS2017大型工厂ERP管理系统源码 工厂通用ERP源码
QObject source code analysis -d pointer and Q pointer
sudo rosdep init Error ROS安装问题解决方案
【口才】谈判说服技巧及策略
【MySQL必知必会】触发器 | 权限管理









