Given that I have something like this:
int val; struct node *mhm;
int val; struct node *next;
I want to extract content on each line, using sed, awk, or grep so that they read:
init->val = val; init->mhm = mhm;
init->val = val; init->next = next;
grep -o outputs each individual result on a new line, but I need to preserve line structure (each group of variables refer to a separate thing).
I use a gnu sed command presently, but I only want to output the replaced string:
sed -re 's/([A-Za-z0-9_]*);/init->\1 = \1;/g'
This above sed command outputs:
int init->val = val; struct node *init->mhm = mhm;
int init->val = val; struct node *init->next = next;
Even when using non-greedy modifiers, I can’t get a full line regex statement to successfully select each variable name in each line.
This works for your sample set(minor change to your solution):