当前位置:网站首页>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
边栏推荐
- Doris learning notes integration with other systems
- 苹果手机端同步不成功,退出登录,结果再也登录不了了
- Numpy basic package for data analysis
- thymeleaf设置disabled
- C language and SQL Server database technology
- Goldfish rhca memoirs: cl210 managing storage -- managing shared file systems
- 应用实践:Paddle分类模型大集成者[PaddleHub、Finetune、prompt]
- 河源市区推出消防安全主题奶茶 助推夏季火灾防控
- 用GaussDB(for Redis)存画像,推荐业务轻松降本60%
- Throwing OutOfMemoryError “Could not allocate JNI Env“
猜你喜欢

苹果官网产品打折 买iPhone 13 Pro Max 可省600元

Filters get the data in data; Filters use data in data

Deep understanding of pytorch distributed parallel processing tool DDP -- starting from bugs in engineering practice

IDEA设置提交SVN时忽略文件配置

Typora无法打开提示安装新版本解决办法

The supply chain collaborative management system, a new "engine" of digitalization in machinery manufacturing industry, helps enterprises' refined management to a new level

Under the epidemic, the biomedical industry may usher in breakthrough development

Realize a family security and environmental monitoring system (I)

~5 new solution of CCF 2021-12-2 sequence query

sqli-labs Basic Challenges Less1-10
随机推荐
变分(Calculus of variations)的概念及运算规则
Throwing OutOfMemoryError “Could not allocate JNI Env“
gson与fastjson
Digital Twins - cognition
基于redis的keys、scan删除ttl为-1的key
Melodic + Realsense D435i 配置及错误问题解决
知名手写笔记软件 招 CTO·坐标深圳
Vs2017 large factory ERP management system source code factory general ERP source code
OverTheWire-Natas
安防市场进入万亿时代,安防B2B网上商城平台精准对接深化企业发展路径
Two Sum
~5 new solution of CCF 2021-12-2 sequence query
PHP website design ideas
How to design a high concurrency system?
The supply chain collaborative management system, a new "engine" of digitalization in machinery manufacturing industry, helps enterprises' refined management to a new level
华为ensp路由器静态路由(默认路由的下一跳地址)
【MySQL必知必会】触发器 | 权限管理
Thymeleaf controls whether display is displayed through style
Idea regular expression replacement (idea regular search)
机械制造业数字化新“引擎”供应链协同管理系统助力企业精细化管理迈上新台阶