1

I have a file like:

{&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 },   

and another file that has 3 records with two fields on each line:

123 fun1   
456 sum_fun
789 multi_fun

I want to write a quick command which will give me something like below:

{&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

You could try something like this:

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
  • Wow, thanks a lot Michael Vehrs for your help. Sincerely. plus1. – Forever Learner Feb 17 '17 at 10:35
  • 1
    @CppLearner You're welcome. – Michael Vehrs Feb 17 '17 at 11:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.