AWK内置变量转换为bash变量 [英] AWK builtin variable to bash variable
问题描述
我想将内置变量FNR分配给bash脚本变量,就像这样,"$ TOT_RECORDS = FNR"
awk'{print NR-1"\ t" $ 0; }''$ INPUT_FILE> $ OUTPUT_FILE
如果我这样做,我将获得每个迭代编号,而我只想要总数;
TOT_RECS = $(awk``{print NR-1;}''$ INPUT_FILE)
还是这个,我确实得到了总数,但是如何将其分配给全局变量?;
awk''END {print NR}''$ INPUT_FILE
通过awk,我想读取输入文件,然后输出到带有前缀行号的新文件,并将总行号返回到全局脚本var中.我在这里还想念什么
wc -l可以毫无麻烦地工作. ;-)
i''m wanting to assign the builtin variable FNR to a bash script variable, something like this, ''$TOT_RECORDS = FNR''
awk ''{ print NR-1 "\t" $0; }'' $INPUT_FILE >$OUTPUT_FILE
and if i do this, i get each iteration number & i only want the total;
TOT_RECS=$(awk ''{ print NR-1; }'' $INPUT_FILE)
or this and i do get the total number, but how to assign it to global var?;
awk ''END {print NR}'' $INPUT_FILE
via awk, i would like to read the input file, then output to new file with prefix line numbers and return total line numbers into a global script var. what am i missing here besides,
`wc -l` would work without all this hassle. ;-)
推荐答案
TOT_RECORDS = FNR''
awk''{print NR-1"\ t"
TOT_RECORDS = FNR''
awk ''{ print NR-1 "\t"
0; }''
INPUT_FILE>
INPUT_FILE >
这篇关于AWK内置变量转换为bash变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!