Skip to main content
6 of 7
added 159 characters in body
user avatar
user avatar

Using SED command

If you want to delete the line containing either '/*' or '*/' you can use:

sed -e '/\*\//d' -e '/\/\*/d' test

You can also save the output by using > and your new file, for instance:

sed -e '/\*\//d' -e '/\/\*/d' test > test2

But if you just want to delete only '/*' and '*/' and not the whole line, you should change the sed command to this one:

sed -e 's/\*\///g' -e 's/\/\*//g' test

Summary

Option '-e command' appends the editing commands specified by the command argument to the list of commands.

's/X//g' will remove the word "X" from lines.

'/X/d' will remove lines containing the word "X"

N.B. if your looking for starting a loop by setting a beginning and end point, You need to write a script in more complex situations. What I wrote, only works when you want to delete lines containing a special character, for example we have two lines of a comment, one starts with a '/*' and the other ends in '*/', what I wrote will work in this case since those lines contain these elements, but if your comment has more lines and some of them ain't containing those special characters, you'll be in need of a script. If you're using scripts written in perl, ruby, or whatsoever else, be aware that you might be in need of removing empty lines after running the script. BTW, you can use sed '/\/\*/,/\*\//d' test but it can only delete lines where there is at least one new line between start and end points. Easiest way for complex situations, is using scripts.

I hope I could be helpful, and precise.

Good Luck

user172564