我有一个像这样的文件:
{&structure_name.field, sizeof(structure_name.field),
&structure_name.field, sizeof(structure_name.field), TODO },
{&structure_name.field, sizeof(structure_name.field),
&structure_name.field, sizeof(structure_name.field), TODO },
{&structure_name.field, sizeof(structure_name.field),
&structure_name.field, sizeof(structure_name.field), TODO },
另一个文件有 3 条记录,每行有两个字段:
123 fun1
456 sum_fun
789 multi_fun
我想写一个快速命令,它会给我类似下面的内容:
{&structure_name.123, sizeof(structure_name.123),
&structure_name.123, sizeof(structure_name.123), fun1 },
{&structure_name.456, sizeof(structure_name.456),
&structure_name.456, sizeof(structure_name.456), sum_fun },
{&structure_name.789, sizeof(structure_name.789),
&structure_name.789, sizeof(structure_name.789), multi_fun },
答案1
你可以尝试这样的事情:
awk 'NR==FNR { a[2*NR] = $1; a[2*NR-1] = $1; b[2*NR] = $2; b[2*NR-1] = $2; next; }
{ gsub(/field/, a[FNR]); gsub(/TODO/, b[FNR]); print; }' patterns input