此行在文本文件中找到该行并打印所选项目,但如何在打印输出中插入文本?
system("/usr/bin/awk '/-1.98/{print $2 $1}' /pathto/myfile.txt")
例如:
system("/usr/bin/awk '/-1.98/{print "Items " $2 " and " $1}' /pathto/myfile.txt")
像第二行那样的东西不断引发对括号的需求。尝试过连接运算符和逗号无济于事。
答案 0 :(得分:0)
您可以使用printf:
system("/usr/bin/awk '/-1.98/{printf "%-s\n", "Items " $2 " and " $1}' /pathto/myfile.txt")
适用于:
system("/usr/bin/awk '/-1.98/{print "Items " $2 " and " $1}' /pathto/myfile.txt")
Ideone链接:http://ideone.com/ivQ4sQ