I am bothered with this for a long time already: I need to match a string in a text file and remove the C-commentary around it. The edit should be inplace or into a new file (I will then move mv-command to push it).
/*
might be text here;
STRING_TO_MATCH
some text;
more text
maybe brackets ( might be text and numbers 123);
*/
So the string is easy to find, but how can I remove the commentary? The number of lines is not always equal. I couldn't figure that out because the removal must be non-greedy (there is similiar data in the same file that shouldn't be altered) and the overall "pattern" is multiline. Desired output:
might be text here;
STRING_TO_MATCH
some text;
more text
maybe brackets ( might be text and numbers 123);
I guess the workflow should be like:
Find string_to_match, find preceding first /* and remove it and then remove following first */.
It would be great if the solution would automatically also work for
/* STRING_TO_MATCH
some text;
more text
maybe brackets ( might be text and numbers 123);
*/
Great thanks in advance from a Bash-amateur! I was not successful with SED. AWK solutions and idiot-proof explanation also welcome. Greetings!