0

My friends! I'm beginner in bash and faced such a problem. I need to find all comments in cpp file (include multiline) and write them in output file. I don't know how to select comments.

#!/bin/bash
name1=$1 #solution.cpp
name2=$2 #out.txt
if [ ${name1: -4} == ".cpp" ]; then
    cat solution.cpp | grep ^\//
else
    echo "bad"
fi
  • 1
    Related: [Regular expression to find C-style comments](https://stackoverflow.com/questions/32916322/regular-expression-to-find-c-style-comments); [Regex to match a C-style multiline comment](https://stackoverflow.com/questions/13014947/regex-to-match-a-c-style-multiline-comment); [How to print comments in a given program?](https://stackoverflow.com/questions/12159055/how-to-print-comments-in-a-given-program) – Charles Duffy May 06 '20 at 22:15
  • 2
    ...one approach you might find interesting (taken from an answer to [How to print comments in a given program?](https://stackoverflow.com/a/12159148/14122)) is the awk script http://amit.chakradeo.net/files/xscc.awk.txt. If you consider it an acceptable answer to your question, please close the question as a duplicate of the one on which the answer was originally posted. If you *don't* consider it an acceptable answer, please edit your question to clarify its differences from the question in which that answer was originally posted. – Charles Duffy May 06 '20 at 22:17

0 Answers0