我还是python的新手。 我有编号列表的文本文件,每个数字有两个“属性”与它一起:python中的shell脚本变量
250 121 6000.654
251 8472 650.15614
252 581 84.2
我要搜索的第一列,并返回第二和第三列作为独立变量,以便我可以稍后使用它们。
cmd = """ cat new.txt | nawk '/'251'/{print $2}' """
os.system(cmd)
这工作,因为它打印$ 2栏,但我想转让本输出到一个变量,像这样(但是这个据我所知返回错误的号码):
cmdOutput = os.system(cmd)
也我想根据变量更改nawk'd值,如下所示:
cmd = """ cat new.txt | nawk '/'$input'/{print $2}' """
如果有人能帮忙,谢谢。
你见过http://stackoverflow.com/questions/6736627/python-command-execution-output/6736689#6736689 – Dirk
你可以给我们的输出,就像它是什么打印? – TheChes44
为什么你想要使用awk,何时可以轻松使用纯Python? – utdemir