用于删除 C++ 注释的 sed 脚本:脚本重复行 [英] Sed script for delete C++ comments: script duplicate the lines
问题描述
我使用这个脚本删除所有带有 sed 的 C/C++ 注释:
Im using this script for delete all C/C++ comments with sed:
http://sed.sourceforge.net/grabbag/scripts/remccoms3.sed
sed -i -f remccoms3.sed Myfile.cpp
但是这个脚本复制了所有的行,例如:
But this script duplicate all the lines, example:
/*-------------------------------------------------------------------------------
This file is part of MyProject.
Author Worvast
#-------------------------------------------------------------------------------*/
#include <fstream>
#include <sstream>
//Other files
#include "Data.h"
#include "utility.h"
// Open input file
std::ifstream input_file;
转换为:
#include <fstream>
#include <fstream>
#include <sstream>
#include <sstream>
#include "Data.h"
#include "Data.h"
#include "utility.h"
#include "utility.h"
std::ifstream input_file;
std::ifstream input_file;
老实说,我不明白 SED 两者都知道错误在哪里.这个问题有什么想法或解决方案吗?
And to be honest I do not understand SED both to understand where is the error. Any idea or solution to this problem?
推荐答案
运行 sed
脚本的预期命令行是 /bin/sed -nf
(来自社帮线).
The intended command line to run that sed
script is /bin/sed -nf
(from the shebang line).
您的命令 (sed -i -f remccoms3.sed
) 省略了 -n
参数.
Your command (sed -i -f remccoms3.sed
) leaves out the -n
argument.
sed
的 -n
参数是
-n, --quiet, --silent
-n, --quiet, --silent
禁止自动打印模式空间
所以没有它你会得到正常的打印和脚本的打印.
so without that you get the normal printing and the script's printing.
这篇关于用于删除 C++ 注释的 sed 脚本:脚本重复行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!