Thanks, your solution answered my question. However, you point out another problem that may appear,i.e., what happens if vary precedes varx. To better explain this point, let me express the problem in its original form, hence slightly different from the simplified one of the previous post.
I'm upgrading my personal software and for compatibility reasons I have to change all my old scripts. Striclty speaking I have the following code:
Quote:
var.applyfield1 = true; % var.applyfield1 can be true or false
% .... some line codes
var.field1type = 'type1'; % var.field1type can be one of the strings: 'type1','type2',...,'typeN'
Please, note that var.applyfield1 is a struct variable.
IF var.applyfield1 = true, at the output I want:
Quote:
var.FIELD1.APPLY = 'type1';
% .... some code lines
therefore both variable assignments regarding var.applyfield1 and var.field1type must be removed and substituted (before or after the "%... some code lines", it doesn't matter) with the new variable var.FIELD1.APPLY
ELSE, IF var.applyfield1 = false, I want:
Quote:
var.FIELD1.APPLY = '';
% .... some line codes
same as before but with a different value for var.FIELD1.APPLY (empty string).
The new problem that I was mentioning at the beginning of this reply is that awk or sed must operate as well even if var.applyfield1 and var.field1type are exchanged. For instance, with;
Quote:
var.field1type = 'type1'; % var.field1type can be one of strings: 'type1','type2',...,'typeN'
% ... some code lines
var.applyfield1 = true; % var.applyfield1 can be true or false
I want the same kind of substitution, namely:
Quote:
var.FIELD1.APPLY = 'type1';
% ...some code lines
The assignments to var.field1type and var.applyfield1 can be safely assumed to appear once in the script.
If possible, I would prefer a solution based on sed because such replacement is just one of many, which can be easily handled with the option -e.
Thanks again,
Paolo