... assuming there is no nesting of braces. Put in a better separator than just a newline if you like. The \A and \Z patterns match beginning of file and end of file, respectively; the middle substitution is the meat of the program.
You are contradicting yourself. If that's not what you want, then what do you want?
Probably it could, if you are handy with sed, but I would not go there. (I have, more times than I care to remember, but it's so much easier in Perl.)
As an aside, you don't need to specify leading and trailing .* wildcards; sed will find the requested pattern anywhere on the line anyway (and in fact you are making it a bit harder for it).
Good Morning ERA,
Your perl magic works fine. It needs a bit of tweaking in my actual test case
perl -0777 -pe 's/(\s*\{.*?\})\s*(\S*);/\2\1;/sg'
Also, irrespective of
struct A{
...
}B;
or enum A{
...
}B;
It moves B up. Could you please help me with making it work for specifically struct scenario. Thanks
One more twist, say
if A exists(non-null) don't move B, just remove it.
Logic:
if A = "";
than
move B before {
else
delete B
Reason for doing this is to handle scnario like
struct A{
...
}A_T;
Your earlier conversion script is able to handle
typedef struct{
...
}A;
and
struct A{
...
};
output has to be
struct A{
...
};
So far we have onlly been doing substitutions. Adding if-then-else logic would require a quite different script. Maybe you could rephrase this using different rules? Like if A is typedef then remove A? That would still be easy to squeeze in.
The (?:...) is just like a regular set of parentheses, except any match is not assigned to \1 or \2, so I didn't have to change the rest of the script. And the trailing ? says the whole thing is optional.
I was confused about putting the struct inside the parens, it needs to go before \2 so I'm keeping it separate after all.
Or you could post-process the output if you can tell after the fact which ones are wrong.