我有一个包含缩进的行诸如文件:添加信息到输出 - 从shell命令执行获得
table 't'
field 'abc'
field 'def' and @enabled=true
field 'ghi'
table 'u'
我想将它变换到:
table 't'
field 'abc' [info about ABC]
field 'def' [info about DEF] and @enabled=true
field 'ghi' [info about GHI]
table 'u'
其中括号之间的串是从一个shell脚本的调用中获得的(get-info
,它提取术语'abc','def'和'ghi'的定义)。
我用AWK试图(通过cmd | getline output
机制):
awk '$1 == "field" {
$2 = substr($2, 2, length($2) - 2)
cmd = "get-info \"" $2 "\" 2>&1 | head -n 1" # results or error
while (cmd | getline output) {
print $0 " [" output "]";
}
close(cmd)
next
}
// { print $0 }'
,但它不尊重压痕!
我怎么能实现我的愿望?
你的问题是非常不清楚的。也许增加你的Awk脚本将有助于澄清你卡住的地方。 – tripleee
我试图更清楚地表达我的要求。希望这可以帮助! – user3341592