I want to remove the multi-line comments in Java
using sed
command. The regex is working if we use character ranges like a-zA-Z0-9
etc. but not in case of word character like wS
.
Test-File content:
hello world /* abcd efgh*/ world hello
Command used :
sed -i -e "s//*[sS]*///" <file>
Expected results:
hello world world hello
Actual results:
hello world abcd efgh*/ world hello
Advertisement
Answer
You can use grep
with a regex (-E
) and inverted matches (-v
), i.e.:
grep -Ev '(/*|*/)' < text.txt
Output:
hello world world hello