当前位置:网站首页>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
边栏推荐
- The security market has entered a trillion era, and the security B2B online mall platform has been accurately connected to deepen the enterprise development path
- 知名手写笔记软件 招 CTO·坐标深圳
- How to design a high concurrency system?
- Quickly set up dobbo demo
- Ten common application scenarios of redis
- English语法_不定代词 - other / another
- Paddlenlp's UIE relationship extraction model [executive relationship extraction as an example]
- PHP website design ideas
- Two Sum
- Detailed explanation of nat/napt address translation (internal and external network communication) technology [Huawei ENSP]
猜你喜欢

Initial flask and simple application

Gameframework making games (I)

PS制作加载GIF图片教程

Typora cannot open the prompt to install a new version solution

手把手教你申请SSL证书
![优质数对的数目[位运算特点+抽象能力考察+分组快速统计]](/img/c9/8f8f0934111f7ae8f8abd656d92f12.png)
优质数对的数目[位运算特点+抽象能力考察+分组快速统计]

MySQL table operation

PS making and loading GIF pictures tutorial
![Application practice: Great integrator of the paddy classification model [paddlehub, finetune, prompt]](/img/b6/62a346174bfa63fe352f9ef7596bfc.png)
Application practice: Great integrator of the paddy classification model [paddlehub, finetune, prompt]

Feiwo technology IPO meeting: annual revenue of 1.13 billion Hunan Cultural Tourism and Yuanli investment are shareholders
随机推荐
GameFramework制作游戏(一)
Idea regular expression replacement (idea regular search)
Numpy basic package for data analysis
That day, I installed a database for my sister... Just help her sort out another shortcut
Famous handwritten note taking software recruit CTO · coordinate Shenzhen
Vs2017 large factory ERP management system source code factory general ERP source code
jqgrid全选取消单行点击取消事件
手把手教你申请SSL证书
Goldfish rhca memoirs: cl210 managing storage -- managing shared file systems
轻松入门自然语言处理系列 12 隐马尔可夫模型
Digital Twins - cognition
Save the image with gaussdb (for redis), and the recommended business can easily reduce the cost by 60%
Gateway 网关报错 SERVICE_UNAVAILABLE
Flask SSTI injection learning
Nuc980 set up SSH xshell connection
Two Sum
PHP website design ideas
PS making and loading GIF pictures tutorial
bond0脚本
Ten common application scenarios of redis