简体   繁体   English

Sed 替换编程语言文件

[英]Sed replace for programming language files

I am using sed to remove comment characters at the beginning using s/${pn_ere}// .我正在使用sed删除开头的注释字符s/${pn_ere}// The delimiter ends up being a problem for C++ code when I have the line start being // .当我的行开始为//时,分隔符最终成为 C++ 代码的问题。

What alternative to / could I use that would be safe to use for most programming languages?对于大多数编程语言/我可以使用什么替代方法来安全使用?

   sed -n "/$beg_re/,/$end_re/ {
      /$beg_re/d ; /$end_re/z; s/${pn_ere}// ; p`

s/${pn_ere}// but have to replace the use of / and use another delimiter. s/${pn_ere}//但必须替换/的使用并使用另一个定界符。 In this way I can handle C++ code where comments start with // .通过这种方式,我可以处理注释以//开头的 C++ 代码。

You could use "_" for example.例如,您可以使用“_”。

See here for more ideas.请参阅此处了解更多想法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM