我有这个代码,但它给了我一个错误
awk '
FNR == NR {
# reading get_ids_only.txt
values[$1] = ""
next
}
BEGIN {
# reading default.txt
for (elem in values){
if ($0 ~ elem){
if (values[elem] == ""){
values[elem] = "\"" $0 "\""
getline;
values[elem] = "\n"" $0 ""\n"
}
else{
values[elem] = values[elem] ", \"" $0 "\""
getline;
values[elem] = values[elem] "\n"" $0 ""\n"
}
}
}
END {
for (elem in values)
print elem " [" values[elem] "]"
}
' get_ids_only.txt default.txt
错误说
awk: syntax error at source line 23
context is
>>> END <<< {
awk: illegal statement at source line 24
awk: illegal statement at source line 24
missing }
这是我的 END{ } 函数开始的地方......
我想做的是..比较文件1中的字符串..如果在文件2中找到字符串,打印字符串并打印它后面的行。然后跳过一个空格。
输入1:
message id "hello"
message id "good bye"
message id "what is cookin"
输入2:
message id "hello"
message value "greetings"
message id "good bye"
message value "limiting"
message id "what is there"
message value "looking for me"
message id "what is cooking"
message value "breakfast plate"
输出:
should print out all the input1, grabbing the message value from input 2.
谁能指导我为什么会发生此错误?
我在我的mac上使用终端。