I'm trying to write a bash script to replace the newline characters and *s from comments, but only if that comment contains a particular substring.
// file.txt
/**
* Here is a multiline
* comment that contains substring
* rest of it
*/
/**
* Here is a multiline
* comment that does not contain subNOTstring
* rest of it
*/
I would like the final result to be:
// file.txt
/** Here is a multiline comment that contains substring rest of it */
/**
* Here is a multiline
* comment that does not contain subNOTstring
* rest of it
*/
I have a regex that matches multiline comments: \/\*([^*]|[\r\n]|(\*+([^*\/]|[\r\n])))*\*\/ but can't figure out the second part, of only matching with the substring, and then replacing all the /n * with just
So to make sure my question is articulated correctly
- Make a match of a substring within a file. i.e. comment
- Make sure that match includes
substring. - Replace all substring within the first match with another string. i.e.
n/ *with
sedwould be an option, or awk or some more flexible programming language (Ruby, Perl). In any case, your approach would fail if the character sequence/**occurs in a context where it does not denote the start of a comment. I don't know about the general syntax of your file, but this would apply for instance to C or PL/1 source code.