Skip to main content
Post Undeleted by CommunityBot
Found a way to only use SED for all cases and no script.
Source Link
user172564
user172564

UsingSolution by Using SED command and no Script

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

sed -e ''s/\*\//d' -e '/\/\*\n&/d'g' test

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

sed -e '/\*\//d'| -esed '/\/\*/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 willThis doesn't 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. BTWon OS X, unless you can useinstall gnu-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 preciseBut it works on Linux Distros.

Good Luck

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

Solution by Using SED command and no Script

Here you are:

sed 's/\*\//\n&/g' test | sed '/\/\*/,/\*\//d'

N.B. This doesn't work on OS X, unless you install gnu-sed. But it works on Linux Distros.

Post Deleted by CommunityBot
added 159 characters in body
Source Link
user172564
user172564

SOLUTION byUsing SED command

If you want to delete the line containing either '/*' or '*/', here you arecan 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

SUMMARYSummary

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 tooto write a script in more complex situations. What I wrote, is only workingworks 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 '*' 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 like usingwritten in perl, ruby, or whatsoever else, be aware that you might be in need of removing empty lines after running the script if. BTW, you hadn't done thatcan 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

SOLUTION by SED command

If you want to delete the line containing either '/*' or '*/', here you are:

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 too write a script in more complex situations. What I wrote, is only working 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 like using perl, ruby, or whatsoever else, be aware that you might be in need of removing empty lines after running the script if you hadn't done that.

I hope I could be helpful, and precise.

Good Luck

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

added 752 characters in body
Source Link
user172564
user172564

SOLUTION by SED command

If you want to delete the line containing either '/*' or '*/', here you are:

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 too write a script in more complex situations. What I wrote, is only working 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 like using perl, ruby, or whatsoever else, be aware that you might be in need of removing empty lines after running the script if you hadn't done that.

I hope I could be helpful, and precise.

Good Luck

SOLUTION by SED command

If you want to delete the line containing either '/*' or '*/', here you are:

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"

Good Luck

SOLUTION by SED command

If you want to delete the line containing either '/*' or '*/', here you are:

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 too write a script in more complex situations. What I wrote, is only working 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 like using perl, ruby, or whatsoever else, be aware that you might be in need of removing empty lines after running the script if you hadn't done that.

I hope I could be helpful, and precise.

Good Luck

added 251 characters in body
Source Link
user172564
user172564
Loading
added 251 characters in body
Source Link
user172564
user172564
Loading
Post Undeleted by CommunityBot
added 242 characters in body
Source Link
user172564
user172564
Loading
Post Deleted by CommunityBot
Source Link
user172564
user172564
Loading