shell - 在 Shell 中的每个空行之后打印所有行
问题描述
我正在尝试在文件中的每个空白行之后打印所有行。任何人都可以在shell中建议一个命令吗?
示例文件:
line1
line2
line 3
line 4
line 5
line 7
line 6
预期输出:
第 3
行 第 4
行 第 5
行 第 7
行 第 6 行
解决方案
您能否尝试在 GNUawk
中仅在显示的示例中进行跟踪、编写和测试。
awk '/^$/{found=1;next} found && !/^$/' Input_file
输出如下。
line 3
line 4
line 5
line 7
line 6
说明:为上述解决方案添加详细说明。
awk ' ##Starting awk program from here.
/^$/{ ##Checking if a line is an empty line then do following.
found=1 ##Setting found to 1 here.
next ##next will skip all further statements from here.
}
found && !/^$/ ##Checking condition if found is SET and line is NOT empty then print that line.
' Input_file ##Mentioning Input_file name here.
推荐阅读
- c++ - 不使用参数调用测试函数
- laravel - 没有得到条件 if 语句和 else 语句
- python - 如何在列表中定义 NA 值并检查 pandas 数据框?
- python - 在python中的if条件中动态添加参数
- blockchain - 有没有办法修复安全帽无法签名
- angular - 传入组件数组作为输入Angular 12
- python - 在字符串序列中寻找三元组的替代方案
- knockout.js - 内循环中的 Knockoutjs 数据绑定问题
- excel - 将 DataGridView 单元格粘贴到 Excel 电子表格
- node.js - 在 socket.io 和 express(node.js) 上获取 CORS EROOR