sed - 我正在寻找一个 sed 命令,以将源代码中的多行注释减少为单行
问题描述
我正在寻找一个 sed 命令来将源文件中的所有注释在Startmarker:之后和endMarker之前(不包括)加入一行。结束标记之前可能有空行,也可能没有。
Startmarker: comments here comments here comments here comments here comments here comments here
comments here comments here comments here comments here comments here comments here comments here comments here comments here comments here comments here.
endMarker code
code
code
code
Startmarker: comments here comments here comments here comments here comments here comments here
comments here comments here comments here comments here comments here comments here comments here comments here comments here comments here comments here.
endMarker
code
code
我试过以下
awk '
/.*Startmarker/,/.*endMarker/ {
if (/\n/)
printf "%s", $0
else
print
}
' file.name
解决方案
找到awk
时设置一个标志Startmarker
:
awk '/Startmarker/ {nonewline=1}
/endMarker/ {nonewline=0}
{ if (nonewline==1) printf("%s",$0); else print $0; }' file.name
推荐阅读
- python - 使用 anaconda 提示符将批量 Labelme json 文件转换为一组图像和标签
- java - 获取 ElasticsearchStatusException 和 ElasticsearchResponseException?
- javascript - 如何使用 CASL 定义 JSON 能力
- electron - setContentProtection 不会从 Mac OS chrome 中隐藏电子应用程序的内容
- java - 无论使用什么日期格式,都需要在一个月内获得正确的输出周数
- python - 如何比较两个数组元素的平方和?
- angular - 将 Angular Firestore 集合数据转换为数组
- sql - 为什么我不能将 .csv 复制到 pgAdmin 4 中的表中?
- google-sheets - ISOWEEKNUM 和 WEEKNUM 函数返回错误值
- java - 在java中初始化默认系统属性