我是gawk的新手,我正在尝试使用.po文件创建一个翻译器。
这是.po文件内容的例子
:quota_by_role.module:73
msgstr“删除了配额。”msgstr“Quota removida。”
我想出了这个。它基本上打印了得到匹配单词的下一行。
awk -F'"' 'match($2, /^word_to_translate$/) {printf "%s", $2": ";getline; print $2}' translator.po translator2.po
结果将是
word_to_translate : something_in_other_language.
它工作正常,但我想知道是否有另一种方法可以不使用“Getline”。
答案 0 :(得分:0)
使用grep
:
grep -A1 "matching-word" filename |grep -v "matching-word"
将打印具有“匹配字”的行的下一行。
答案 1 :(得分:0)
awk -F'"' '{ if (found){print;exit} }
$2 ~ /word-to-translate/{ found=1 }'