我如何可以传递AWK变量,一个shell命令? [英] How can I pass variables from awk to a shell command?
本文介绍了我如何可以传递AWK变量,一个shell命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从awk的一个文件的每一行中运行一个shell命令,shell命令需要一个输入参数。我试图用系统()
,但它并不能识别输入参数。
该文件的每一行是一个文件的地址,我想运行一个命令来处理该文件。因此,一个简单的例子,我想用'厕所'命令的每一行,并通过 $ 1
到厕所。
的awk'{系统(WC $ 1)}'MYFILE
解决方案
你靠近。你必须串联使用awk变量的命令行:
的awk'{系统(WC$ 1)}'MYFILE
I am trying to run a shell command from within awk for each line of a file, and the shell command needs one input argument. I tried to use system()
, but it didn't recognize the input argument.
Each line of this file is an address of a file, and I want to run a command to process that file. So, for a simple example I want to use 'wc' command for each line and pass $1
to wc.
awk '{system("wc $1")}' myfile
解决方案
you are close. you have to concatenate the command line with awk variables:
awk '{system("wc "$1)}' myfile
这篇关于我如何可以传递AWK变量,一个shell命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文