2

I've manually removed some superfluous //------------------------------------- comments from all c++ files within a folder and its subfolders here .

Now I thought that it might be possible to replace "//<unknown number of dashes><line break>" with an empty string or a line break via a shell script.

Afterwards I'd want to replace three consecutive line breaks with two line breaks.

Could someone tell me how to achieve this with a shell script?

2
  • C++ or Shell script? You tag it C++ while talking about shell script in question. Please make it clear. Commented Feb 22, 2014 at 15:34
  • I meant a shell command/script to remove comments from c++ files Commented Feb 22, 2014 at 15:39

2 Answers 2

1

To remove all C++ style comments that contain only dashes and optional trailing whitespace:

sed 's|//--* *$||' -i file.cpp

To remove trailing whitespace:

sed 's/ *$//' -i file.cpp
Sign up to request clarification or add additional context in comments.

2 Comments

Does that also remove useful comments?
Sorry. yes, it does. I'll edit the post immediately.
0

I added SzG's command to this one to get it to run recursively:

find . -name '*.cxx' | xargs sed 's|// --* *$||' -i

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.