在不同组的行之间添加空行 [英] Add blank line between lines from different groups

查看:13
本文介绍了在不同组的行之间添加空行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个格式为(频率、文件名、代码行)的文件 A:

I have a file A of the form (frequency,file name,code lines):

1 file_name1 code_line1
2 file_name2 code_line2
2 file_name2 code_line3
2 file_name3 code_line4
2 file_name3 code_line5
3 file_name4 code_line6
3 file_name4 code_line7
3 file_name4 code_line8

我希望输出 B 为:

1 file_name1 code_line1

2 file_name2 code_line2
2 file_name2 code_line3

2 file_name3 code_line4
2 file_name3 code_line5

3 file_name4 code_line6
3 file_name4 code_line7
3 file_name4 code_line8

基本上文件 A 包含文件名和文件中的代码行,第一个字段是频率,即文件中的代码行数.

Basically the file A contains file name and code lines from the file and the first field is the frequency, i.e., number of code lines in the file.

我应该明智地通过这些代码行文件.我发现它很乏味,如果不同文件的条目之间存在行间距,那么对我来说会更容易,从而获得所需的输出.

I am supposed to go through these code lines file wise. I am finding it tedious and it would be easier for me if there was a line gap between entries of different files, hence the desired output.

推荐答案

Awk 可以做到:

awk '{if(NR > 1 && $2 != prev_two){printf "
";} prev_two=$2; print $0}' A

A 是文件名.

这篇关于在不同组的行之间添加空行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆