首页 > 解决方案 > 将 cpp 文件中的注释写入 txt 文件

问题描述

我的朋友!我是 bash 的初学者,遇到了这样的问题。我需要在 cpp 文件中找到所有注释(包括多行)并将它们写入输出文件。我不知道如何选择评论。

#!/bin/bash
name1=$1 #solution.cpp
name2=$2 #out.txt
if [ ${name1: -4} == ".cpp" ]; then
    cat solution.cpp | grep ^\//
else
    echo "bad"
fi

标签: linuxbash

解决方案


推荐阅读