Removing c-style comments with sed
Clash Royale CLAN TAG#URR8PPP
I need to delete some kind of characteristic, single line C++ comments from all files in our repository. Code looks something like this:
some_code
// characteristic_comment_to_delete
some_more_code // another_comment
another_line_with_code // characteristic_comment_to_delete
even_more_code
As a result, I would like to get this:
some_code
some_more_code // another_comment
another_line_with_code
even_more_code
I used sed command that makes my result almost as good as I would like:
$ sed -i -e 's&// characteristic_comment_to_delete.*&&g' some_file.cpp
some_code
some_more_code // another_comment
another_line_with_code
even_more_code
Unfortunately, leaving those blank lines is unacceptable solution, so I need somehow improve my command so that it removes whole line, but only if it is left blank after removing this specific comment.
EDIT:
I obviously did not run those commands as root. Changed prompt accordingly.
Also, I did not want to remove all comments, so I do not think that my topic is duplicating other threads.
linux sed
add a comment |
I need to delete some kind of characteristic, single line C++ comments from all files in our repository. Code looks something like this:
some_code
// characteristic_comment_to_delete
some_more_code // another_comment
another_line_with_code // characteristic_comment_to_delete
even_more_code
As a result, I would like to get this:
some_code
some_more_code // another_comment
another_line_with_code
even_more_code
I used sed command that makes my result almost as good as I would like:
$ sed -i -e 's&// characteristic_comment_to_delete.*&&g' some_file.cpp
some_code
some_more_code // another_comment
another_line_with_code
even_more_code
Unfortunately, leaving those blank lines is unacceptable solution, so I need somehow improve my command so that it removes whole line, but only if it is left blank after removing this specific comment.
EDIT:
I obviously did not run those commands as root. Changed prompt accordingly.
Also, I did not want to remove all comments, so I do not think that my topic is duplicating other threads.
linux sed
@jimmij, the OP doesn't want to remove all comments, only// characteristic_comment_to_delete
– Stéphane Chazelas
Mar 1 at 15:16
For C-style comments, How can I delete all characters falling under /* .... */ including /* & */? would be a closer match.
– Stéphane Chazelas
Mar 1 at 15:16
Off topic, but you're not really running this command as root, are you? That#
prompt makes my eye twitch.
– David Conrad
Mar 1 at 18:43
2
Possible duplicate of Remove comments in a C file
– MCCCS
Mar 1 at 19:07
Possible duplicate of How can I remove all comments from a file?
– elbarna
Mar 3 at 10:27
add a comment |
I need to delete some kind of characteristic, single line C++ comments from all files in our repository. Code looks something like this:
some_code
// characteristic_comment_to_delete
some_more_code // another_comment
another_line_with_code // characteristic_comment_to_delete
even_more_code
As a result, I would like to get this:
some_code
some_more_code // another_comment
another_line_with_code
even_more_code
I used sed command that makes my result almost as good as I would like:
$ sed -i -e 's&// characteristic_comment_to_delete.*&&g' some_file.cpp
some_code
some_more_code // another_comment
another_line_with_code
even_more_code
Unfortunately, leaving those blank lines is unacceptable solution, so I need somehow improve my command so that it removes whole line, but only if it is left blank after removing this specific comment.
EDIT:
I obviously did not run those commands as root. Changed prompt accordingly.
Also, I did not want to remove all comments, so I do not think that my topic is duplicating other threads.
linux sed
I need to delete some kind of characteristic, single line C++ comments from all files in our repository. Code looks something like this:
some_code
// characteristic_comment_to_delete
some_more_code // another_comment
another_line_with_code // characteristic_comment_to_delete
even_more_code
As a result, I would like to get this:
some_code
some_more_code // another_comment
another_line_with_code
even_more_code
I used sed command that makes my result almost as good as I would like:
$ sed -i -e 's&// characteristic_comment_to_delete.*&&g' some_file.cpp
some_code
some_more_code // another_comment
another_line_with_code
even_more_code
Unfortunately, leaving those blank lines is unacceptable solution, so I need somehow improve my command so that it removes whole line, but only if it is left blank after removing this specific comment.
EDIT:
I obviously did not run those commands as root. Changed prompt accordingly.
Also, I did not want to remove all comments, so I do not think that my topic is duplicating other threads.
linux sed
linux sed
edited Mar 6 at 8:54
forteller
asked Mar 1 at 13:26
fortellerforteller
133
133
@jimmij, the OP doesn't want to remove all comments, only// characteristic_comment_to_delete
– Stéphane Chazelas
Mar 1 at 15:16
For C-style comments, How can I delete all characters falling under /* .... */ including /* & */? would be a closer match.
– Stéphane Chazelas
Mar 1 at 15:16
Off topic, but you're not really running this command as root, are you? That#
prompt makes my eye twitch.
– David Conrad
Mar 1 at 18:43
2
Possible duplicate of Remove comments in a C file
– MCCCS
Mar 1 at 19:07
Possible duplicate of How can I remove all comments from a file?
– elbarna
Mar 3 at 10:27
add a comment |
@jimmij, the OP doesn't want to remove all comments, only// characteristic_comment_to_delete
– Stéphane Chazelas
Mar 1 at 15:16
For C-style comments, How can I delete all characters falling under /* .... */ including /* & */? would be a closer match.
– Stéphane Chazelas
Mar 1 at 15:16
Off topic, but you're not really running this command as root, are you? That#
prompt makes my eye twitch.
– David Conrad
Mar 1 at 18:43
2
Possible duplicate of Remove comments in a C file
– MCCCS
Mar 1 at 19:07
Possible duplicate of How can I remove all comments from a file?
– elbarna
Mar 3 at 10:27
@jimmij, the OP doesn't want to remove all comments, only
// characteristic_comment_to_delete
– Stéphane Chazelas
Mar 1 at 15:16
@jimmij, the OP doesn't want to remove all comments, only
// characteristic_comment_to_delete
– Stéphane Chazelas
Mar 1 at 15:16
For C-style comments, How can I delete all characters falling under /* .... */ including /* & */? would be a closer match.
– Stéphane Chazelas
Mar 1 at 15:16
For C-style comments, How can I delete all characters falling under /* .... */ including /* & */? would be a closer match.
– Stéphane Chazelas
Mar 1 at 15:16
Off topic, but you're not really running this command as root, are you? That
#
prompt makes my eye twitch.– David Conrad
Mar 1 at 18:43
Off topic, but you're not really running this command as root, are you? That
#
prompt makes my eye twitch.– David Conrad
Mar 1 at 18:43
2
2
Possible duplicate of Remove comments in a C file
– MCCCS
Mar 1 at 19:07
Possible duplicate of Remove comments in a C file
– MCCCS
Mar 1 at 19:07
Possible duplicate of How can I remove all comments from a file?
– elbarna
Mar 3 at 10:27
Possible duplicate of How can I remove all comments from a file?
– elbarna
Mar 3 at 10:27
add a comment |
5 Answers
5
active
oldest
votes
Sed has a d
command for deleting whole lines - it can also take an arbitrary (non /
) delimiter, however it needs to be escaped with on first use. So you could do something like
$ sed -e '#^// characteristic_comment_to_delete$#d' -e 's#// characteristic_comment_to_delete.*##' file
some_code
some_more_code // another_comment
another_line_with_code
even_more_code
to first delete lines that consist entirely of // characteristic_comment_to_delete
, then substitute any remaining occurrences.
(I changed your &
to #
to avoid confusion with the sed &
replacement operator).
add a comment |
With GNU sed
:
sed 's|s*// characteristic_comment_to_delete.*||;T;/./!d'
T
is a GNU extension that branches off unless the previous s
substitution was successful. So if no comment was removed, we branch off, and the next /./!d
(which deletes the line unless it contains at least one character) is skipped.
Standard equivalent:
sed '/[[:space:]]*// characteristic_comment_to_delete.*/s///;/./!d;'
Or:
sed 's|[[:space:]]*// characteristic_comment_to_delete.*||
t 1
b
:1
/./!d'
Both suppress empty lines only if the substitution was successful.
add a comment |
If you accept an AWK solution:
awk -F "[ ]*//[ ]*characteristic_comment_to_delete.*" '$1 != "" print $1; ' some_file.cpp
Note: The pattern contains a space and a TAB between the brackets [ ]
.
This solution does not correctly handle string literals containing the comment pattern, e.g.char text = "// characteristic_comment_to_delete bla bla";
add a comment |
Demonstrating storing the comment in a shell variable, and escaping the slash characters with shell parameter expansion. Otherwise, same as steeldriver's answer.
$ comment='// characteristic_comment_to_delete'
$ sed -e "/^[[:blank:]]*$comment////\//d" -e "s/$comment////\/.*//" file
some_code
some_more_code // another_comment
another_line_with_code
even_more_code
add a comment |
My trivial task of removing specific comments became much more complicated than I anticipated, but I found a working solution that I split into few separate commands.
Main problem was that I had such lines:
another_line_with_code // characteristic_comment_to_delete#xA;more_code // characteristic_comment_to_delete // characteristic_comment_to_delete
#xA; is new line character, but file was written in a way that for sed it was seen as single line.
I had to use perl, as I could not go around the fact, that sed was too greedy despite having theoretically good regex.
Final solution that enabled me to remove lines which contained only comments was (thank you steeldriver for pointing me towards 'd' parameter, I was not aware of that):
$ find . -type f -print0 | xargs -0 sed -i -e '#^// characteristic_comment_to_deletes*$#d'
And to remove in-line comments:
$ find . -type f -print0 | xargs -0 perl -pi -e 's|s*// characteristic_comment_to_deletes*
||g'
+
$ find . -type f -print0 | xargs -0 perl -pi -e 's|
// characteristic_comment_to_deletes*||g'
+
$ find . -type f -print0 | xargs -0 perl -pi -e 's|s*// characteristic_comment_to_deletes*||g'
Could probably easily go down to just two commands, and maybe catch all cases with only single command, but above got the job done. Thanks to everyone!
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f503784%2fremoving-c-style-comments-with-sed%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sed has a d
command for deleting whole lines - it can also take an arbitrary (non /
) delimiter, however it needs to be escaped with on first use. So you could do something like
$ sed -e '#^// characteristic_comment_to_delete$#d' -e 's#// characteristic_comment_to_delete.*##' file
some_code
some_more_code // another_comment
another_line_with_code
even_more_code
to first delete lines that consist entirely of // characteristic_comment_to_delete
, then substitute any remaining occurrences.
(I changed your &
to #
to avoid confusion with the sed &
replacement operator).
add a comment |
Sed has a d
command for deleting whole lines - it can also take an arbitrary (non /
) delimiter, however it needs to be escaped with on first use. So you could do something like
$ sed -e '#^// characteristic_comment_to_delete$#d' -e 's#// characteristic_comment_to_delete.*##' file
some_code
some_more_code // another_comment
another_line_with_code
even_more_code
to first delete lines that consist entirely of // characteristic_comment_to_delete
, then substitute any remaining occurrences.
(I changed your &
to #
to avoid confusion with the sed &
replacement operator).
add a comment |
Sed has a d
command for deleting whole lines - it can also take an arbitrary (non /
) delimiter, however it needs to be escaped with on first use. So you could do something like
$ sed -e '#^// characteristic_comment_to_delete$#d' -e 's#// characteristic_comment_to_delete.*##' file
some_code
some_more_code // another_comment
another_line_with_code
even_more_code
to first delete lines that consist entirely of // characteristic_comment_to_delete
, then substitute any remaining occurrences.
(I changed your &
to #
to avoid confusion with the sed &
replacement operator).
Sed has a d
command for deleting whole lines - it can also take an arbitrary (non /
) delimiter, however it needs to be escaped with on first use. So you could do something like
$ sed -e '#^// characteristic_comment_to_delete$#d' -e 's#// characteristic_comment_to_delete.*##' file
some_code
some_more_code // another_comment
another_line_with_code
even_more_code
to first delete lines that consist entirely of // characteristic_comment_to_delete
, then substitute any remaining occurrences.
(I changed your &
to #
to avoid confusion with the sed &
replacement operator).
answered Mar 1 at 13:37
steeldriversteeldriver
37.6k45389
37.6k45389
add a comment |
add a comment |
With GNU sed
:
sed 's|s*// characteristic_comment_to_delete.*||;T;/./!d'
T
is a GNU extension that branches off unless the previous s
substitution was successful. So if no comment was removed, we branch off, and the next /./!d
(which deletes the line unless it contains at least one character) is skipped.
Standard equivalent:
sed '/[[:space:]]*// characteristic_comment_to_delete.*/s///;/./!d;'
Or:
sed 's|[[:space:]]*// characteristic_comment_to_delete.*||
t 1
b
:1
/./!d'
Both suppress empty lines only if the substitution was successful.
add a comment |
With GNU sed
:
sed 's|s*// characteristic_comment_to_delete.*||;T;/./!d'
T
is a GNU extension that branches off unless the previous s
substitution was successful. So if no comment was removed, we branch off, and the next /./!d
(which deletes the line unless it contains at least one character) is skipped.
Standard equivalent:
sed '/[[:space:]]*// characteristic_comment_to_delete.*/s///;/./!d;'
Or:
sed 's|[[:space:]]*// characteristic_comment_to_delete.*||
t 1
b
:1
/./!d'
Both suppress empty lines only if the substitution was successful.
add a comment |
With GNU sed
:
sed 's|s*// characteristic_comment_to_delete.*||;T;/./!d'
T
is a GNU extension that branches off unless the previous s
substitution was successful. So if no comment was removed, we branch off, and the next /./!d
(which deletes the line unless it contains at least one character) is skipped.
Standard equivalent:
sed '/[[:space:]]*// characteristic_comment_to_delete.*/s///;/./!d;'
Or:
sed 's|[[:space:]]*// characteristic_comment_to_delete.*||
t 1
b
:1
/./!d'
Both suppress empty lines only if the substitution was successful.
With GNU sed
:
sed 's|s*// characteristic_comment_to_delete.*||;T;/./!d'
T
is a GNU extension that branches off unless the previous s
substitution was successful. So if no comment was removed, we branch off, and the next /./!d
(which deletes the line unless it contains at least one character) is skipped.
Standard equivalent:
sed '/[[:space:]]*// characteristic_comment_to_delete.*/s///;/./!d;'
Or:
sed 's|[[:space:]]*// characteristic_comment_to_delete.*||
t 1
b
:1
/./!d'
Both suppress empty lines only if the substitution was successful.
edited Mar 1 at 18:43
answered Mar 1 at 15:12
Stéphane ChazelasStéphane Chazelas
312k57589946
312k57589946
add a comment |
add a comment |
If you accept an AWK solution:
awk -F "[ ]*//[ ]*characteristic_comment_to_delete.*" '$1 != "" print $1; ' some_file.cpp
Note: The pattern contains a space and a TAB between the brackets [ ]
.
This solution does not correctly handle string literals containing the comment pattern, e.g.char text = "// characteristic_comment_to_delete bla bla";
add a comment |
If you accept an AWK solution:
awk -F "[ ]*//[ ]*characteristic_comment_to_delete.*" '$1 != "" print $1; ' some_file.cpp
Note: The pattern contains a space and a TAB between the brackets [ ]
.
This solution does not correctly handle string literals containing the comment pattern, e.g.char text = "// characteristic_comment_to_delete bla bla";
add a comment |
If you accept an AWK solution:
awk -F "[ ]*//[ ]*characteristic_comment_to_delete.*" '$1 != "" print $1; ' some_file.cpp
Note: The pattern contains a space and a TAB between the brackets [ ]
.
This solution does not correctly handle string literals containing the comment pattern, e.g.char text = "// characteristic_comment_to_delete bla bla";
If you accept an AWK solution:
awk -F "[ ]*//[ ]*characteristic_comment_to_delete.*" '$1 != "" print $1; ' some_file.cpp
Note: The pattern contains a space and a TAB between the brackets [ ]
.
This solution does not correctly handle string literals containing the comment pattern, e.g.char text = "// characteristic_comment_to_delete bla bla";
answered Mar 1 at 14:06
BodoBodo
2,271618
2,271618
add a comment |
add a comment |
Demonstrating storing the comment in a shell variable, and escaping the slash characters with shell parameter expansion. Otherwise, same as steeldriver's answer.
$ comment='// characteristic_comment_to_delete'
$ sed -e "/^[[:blank:]]*$comment////\//d" -e "s/$comment////\/.*//" file
some_code
some_more_code // another_comment
another_line_with_code
even_more_code
add a comment |
Demonstrating storing the comment in a shell variable, and escaping the slash characters with shell parameter expansion. Otherwise, same as steeldriver's answer.
$ comment='// characteristic_comment_to_delete'
$ sed -e "/^[[:blank:]]*$comment////\//d" -e "s/$comment////\/.*//" file
some_code
some_more_code // another_comment
another_line_with_code
even_more_code
add a comment |
Demonstrating storing the comment in a shell variable, and escaping the slash characters with shell parameter expansion. Otherwise, same as steeldriver's answer.
$ comment='// characteristic_comment_to_delete'
$ sed -e "/^[[:blank:]]*$comment////\//d" -e "s/$comment////\/.*//" file
some_code
some_more_code // another_comment
another_line_with_code
even_more_code
Demonstrating storing the comment in a shell variable, and escaping the slash characters with shell parameter expansion. Otherwise, same as steeldriver's answer.
$ comment='// characteristic_comment_to_delete'
$ sed -e "/^[[:blank:]]*$comment////\//d" -e "s/$comment////\/.*//" file
some_code
some_more_code // another_comment
another_line_with_code
even_more_code
answered Mar 1 at 17:42
glenn jackmanglenn jackman
52.8k573114
52.8k573114
add a comment |
add a comment |
My trivial task of removing specific comments became much more complicated than I anticipated, but I found a working solution that I split into few separate commands.
Main problem was that I had such lines:
another_line_with_code // characteristic_comment_to_delete#xA;more_code // characteristic_comment_to_delete // characteristic_comment_to_delete
#xA; is new line character, but file was written in a way that for sed it was seen as single line.
I had to use perl, as I could not go around the fact, that sed was too greedy despite having theoretically good regex.
Final solution that enabled me to remove lines which contained only comments was (thank you steeldriver for pointing me towards 'd' parameter, I was not aware of that):
$ find . -type f -print0 | xargs -0 sed -i -e '#^// characteristic_comment_to_deletes*$#d'
And to remove in-line comments:
$ find . -type f -print0 | xargs -0 perl -pi -e 's|s*// characteristic_comment_to_deletes*
||g'
+
$ find . -type f -print0 | xargs -0 perl -pi -e 's|
// characteristic_comment_to_deletes*||g'
+
$ find . -type f -print0 | xargs -0 perl -pi -e 's|s*// characteristic_comment_to_deletes*||g'
Could probably easily go down to just two commands, and maybe catch all cases with only single command, but above got the job done. Thanks to everyone!
add a comment |
My trivial task of removing specific comments became much more complicated than I anticipated, but I found a working solution that I split into few separate commands.
Main problem was that I had such lines:
another_line_with_code // characteristic_comment_to_delete#xA;more_code // characteristic_comment_to_delete // characteristic_comment_to_delete
#xA; is new line character, but file was written in a way that for sed it was seen as single line.
I had to use perl, as I could not go around the fact, that sed was too greedy despite having theoretically good regex.
Final solution that enabled me to remove lines which contained only comments was (thank you steeldriver for pointing me towards 'd' parameter, I was not aware of that):
$ find . -type f -print0 | xargs -0 sed -i -e '#^// characteristic_comment_to_deletes*$#d'
And to remove in-line comments:
$ find . -type f -print0 | xargs -0 perl -pi -e 's|s*// characteristic_comment_to_deletes*
||g'
+
$ find . -type f -print0 | xargs -0 perl -pi -e 's|
// characteristic_comment_to_deletes*||g'
+
$ find . -type f -print0 | xargs -0 perl -pi -e 's|s*// characteristic_comment_to_deletes*||g'
Could probably easily go down to just two commands, and maybe catch all cases with only single command, but above got the job done. Thanks to everyone!
add a comment |
My trivial task of removing specific comments became much more complicated than I anticipated, but I found a working solution that I split into few separate commands.
Main problem was that I had such lines:
another_line_with_code // characteristic_comment_to_delete#xA;more_code // characteristic_comment_to_delete // characteristic_comment_to_delete
#xA; is new line character, but file was written in a way that for sed it was seen as single line.
I had to use perl, as I could not go around the fact, that sed was too greedy despite having theoretically good regex.
Final solution that enabled me to remove lines which contained only comments was (thank you steeldriver for pointing me towards 'd' parameter, I was not aware of that):
$ find . -type f -print0 | xargs -0 sed -i -e '#^// characteristic_comment_to_deletes*$#d'
And to remove in-line comments:
$ find . -type f -print0 | xargs -0 perl -pi -e 's|s*// characteristic_comment_to_deletes*
||g'
+
$ find . -type f -print0 | xargs -0 perl -pi -e 's|
// characteristic_comment_to_deletes*||g'
+
$ find . -type f -print0 | xargs -0 perl -pi -e 's|s*// characteristic_comment_to_deletes*||g'
Could probably easily go down to just two commands, and maybe catch all cases with only single command, but above got the job done. Thanks to everyone!
My trivial task of removing specific comments became much more complicated than I anticipated, but I found a working solution that I split into few separate commands.
Main problem was that I had such lines:
another_line_with_code // characteristic_comment_to_delete#xA;more_code // characteristic_comment_to_delete // characteristic_comment_to_delete
#xA; is new line character, but file was written in a way that for sed it was seen as single line.
I had to use perl, as I could not go around the fact, that sed was too greedy despite having theoretically good regex.
Final solution that enabled me to remove lines which contained only comments was (thank you steeldriver for pointing me towards 'd' parameter, I was not aware of that):
$ find . -type f -print0 | xargs -0 sed -i -e '#^// characteristic_comment_to_deletes*$#d'
And to remove in-line comments:
$ find . -type f -print0 | xargs -0 perl -pi -e 's|s*// characteristic_comment_to_deletes*
||g'
+
$ find . -type f -print0 | xargs -0 perl -pi -e 's|
// characteristic_comment_to_deletes*||g'
+
$ find . -type f -print0 | xargs -0 perl -pi -e 's|s*// characteristic_comment_to_deletes*||g'
Could probably easily go down to just two commands, and maybe catch all cases with only single command, but above got the job done. Thanks to everyone!
answered Mar 6 at 8:32
fortellerforteller
133
133
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f503784%2fremoving-c-style-comments-with-sed%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
@jimmij, the OP doesn't want to remove all comments, only
// characteristic_comment_to_delete
– Stéphane Chazelas
Mar 1 at 15:16
For C-style comments, How can I delete all characters falling under /* .... */ including /* & */? would be a closer match.
– Stéphane Chazelas
Mar 1 at 15:16
Off topic, but you're not really running this command as root, are you? That
#
prompt makes my eye twitch.– David Conrad
Mar 1 at 18:43
2
Possible duplicate of Remove comments in a C file
– MCCCS
Mar 1 at 19:07
Possible duplicate of How can I remove all comments from a file?
– elbarna
Mar 3 at 10:27