【发布时间】:2016-06-20 03:56:10
【问题描述】:
我有包含缩进行的文件,例如:
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 脚本将有助于澄清您卡在哪里。
-
我试图更清楚地表达我的要求。希望这会有所帮助!