对行组进行排序
我有一个文本文件,如下所示,
iv_destination_code_10
TAP310_mapping_RATERUSG_iv_destination_code_10
RATERUSG.iv_destination_code_10 = WORK.maf_feature_info[53,6]
iv_destination_code_2
TAP310_mapping_RATERUSG_iv_destination_code_2
RATERUSG.iv_destination_code_2 = WORK.maf_feature_info[1,6]
iv_destination_code_3
TAP310_mapping_RATERUSG_iv_destination_code_3
RATERUSG.iv_destination_code_3 = WORK.maf_feature_info[7,6]
iv_destination_code_4
TAP310_mapping_RATERUSG_iv_destination_code_4
RATERUSG.iv_destination_code_4 = WORK.maf_feature_info[13,6]
iv_destination_code_5
TAP310_mapping_RATERUSG_iv_destination_code_5
RATERUSG.iv_destination_code_5 = WORK.maf_feature_info[19,6]
iv_destination_code_6
TAP310_mapping_RATERUSG_iv_destination_code_6
RATERUSG.iv_destination_code_6 = WORK.maf_feature_info[29,6]
iv_destination_code_7
TAP310_mapping_RATERUSG_iv_destination_code_7
RATERUSG.iv_destination_code_7 = WORK.maf_feature_info[35,6]
iv_destination_code_8
TAP310_mapping_RATERUSG_iv_destination_code_8
RATERUSG.iv_destination_code_8 = WORK.maf_feature_info[41,6]
iv_destination_code_9
TAP310_mapping_RATERUSG_iv_destination_code_9
RATERUSG.iv_destination_code_9 = WORK.maf_feature_info[47,6]
三行组合形成一个单元:
iv_destination_code_9
TAP310_mapping_RATERUSG_iv_destination_code_9
RATERUSG.iv_destination_code_9 = WORK.maf_feature_info[47,6]
是一个单元。
iv_destination_code_9
9 表示我必须排序的数字 10 9 8....
我需要一个 shell 脚本/awk,它将按降序对单位进行排序。 这怎么可能?
I have a text file like below
iv_destination_code_10
TAP310_mapping_RATERUSG_iv_destination_code_10
RATERUSG.iv_destination_code_10 = WORK.maf_feature_info[53,6]
iv_destination_code_2
TAP310_mapping_RATERUSG_iv_destination_code_2
RATERUSG.iv_destination_code_2 = WORK.maf_feature_info[1,6]
iv_destination_code_3
TAP310_mapping_RATERUSG_iv_destination_code_3
RATERUSG.iv_destination_code_3 = WORK.maf_feature_info[7,6]
iv_destination_code_4
TAP310_mapping_RATERUSG_iv_destination_code_4
RATERUSG.iv_destination_code_4 = WORK.maf_feature_info[13,6]
iv_destination_code_5
TAP310_mapping_RATERUSG_iv_destination_code_5
RATERUSG.iv_destination_code_5 = WORK.maf_feature_info[19,6]
iv_destination_code_6
TAP310_mapping_RATERUSG_iv_destination_code_6
RATERUSG.iv_destination_code_6 = WORK.maf_feature_info[29,6]
iv_destination_code_7
TAP310_mapping_RATERUSG_iv_destination_code_7
RATERUSG.iv_destination_code_7 = WORK.maf_feature_info[35,6]
iv_destination_code_8
TAP310_mapping_RATERUSG_iv_destination_code_8
RATERUSG.iv_destination_code_8 = WORK.maf_feature_info[41,6]
iv_destination_code_9
TAP310_mapping_RATERUSG_iv_destination_code_9
RATERUSG.iv_destination_code_9 = WORK.maf_feature_info[47,6]
combination of three lines form a unit:
iv_destination_code_9
TAP310_mapping_RATERUSG_iv_destination_code_9
RATERUSG.iv_destination_code_9 = WORK.maf_feature_info[47,6]
is one unit.
iv_destination_code_9
9 indicates the number by which i have to sort
10
9
8....
i need a shell script/awk which will sort the units in a descending order.
how is it possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
首先,所有行尾都替换为
#
,并重新创建块末尾的行尾 (]#
)。然后对第四个字段执行数字反向排序,字段之间用
_
分隔。最后,检索原始行尾。
First all end of lines are replaced by
#
, and end of lines at the end of blocks (]#
) are recreated.Then a numeric reverse sort is performed on the fourth field with fields separated by
_
.Finally, original end of lines are retrieved.
或与呆呆
Or with gawk
这与 mouvicel 的答案类似,但使用非打印字符作为特殊标记(并假设原始文件不包含它们)。
它假设原始文件中没有空行,因为它在末尾删除了它们。它还依赖于每个组结束行以“]”结尾。
This works similarly to mouvicel's answer, but uses non-printing characters as the special markers (and assumes that the original file doesn't contain them).
It assumes that there are no blank lines in the original file since it deletes them at the end. It also relies on every group-ending line to end in "]".