Windowsで使用awk
しています。というスクリプトがありますtest.awk
。このスクリプトは、ファイルを読み取り、特定のフィールド (キー) を値に置き換える必要があります。key->value リストは、 というファイルにありますtranslate.txt
。
その構造は次のようになります。
e;Emil
f;Friedrich
g;Gustaf
h;Heinrich
i;Ida
簡単な例では、私の入力ファイルは次のようになります
e,111
f,222
g,333
h,444
i,555
..
したがって、出力は
Emil,111
Friedrich,222
Gustaf,333
Heinrich,444
Ida,555
..
私が持っているスクリプトは、ユーザー関数を使用して置換を行っていますが、この関数に別のファイルをソースとしてkey2value
与えることに成功していません。translate.txt
私のコードを見てください:
{
FS=","
d=key2value($1)
print d "," $2
}
function key2value(b)
{
#this should use another file, not the currently processed one
FILENAME="translate.txt"
begin
{
FS=";"
if ($1=b)
{
return $2
}
end
}
もう1つ、FSにはバグがあり、2行目からのみ機能します。