【发布时间】:2016-08-08 08:08:24
【问题描述】:
我有一个巨大的文件,我需要对模式匹配“vm”的 3 行进行排序和合并,并将它们合并到单行中,如下所示
kfg-ap4 是服务器名称,我们只能拥有它一次,在排序时会很好.. 我用 getline 尝试了 awk,但不知何故我想不适合它..
awk '/vm/ {printf $0 " ";getline;打印 $0}' mem_overc
**[kfg-ap4] out: vm.overcommit_memory = 0 [kfg-ap4] out: vm.overcommit_ratio = 50 [kfg-ap4] out: vm.nr_overcommit_hugepages = 0**
[kfg-ap4] Executing task 'moc'
[kfg-ap4] sudo: /sbin/sysctl -A | grep overcommit
[kfg-ap4] out:
[kfg-ap4] out: We trust you have received the usual lecture from the local System
[kfg-ap4] out: Administrator. It usually boils down to these three things:
[kfg-ap4] out:
[kfg-ap4] out: #1) Respect the privacy of others.
[kfg-ap4] out: #2) Think before you type.
[kfg-ap4] out: #3) With great power comes great responsibility.
[kfg-ap4] out:
[kfg-ap4] out: sudo password:
[kfg-ap4] out: vm.overcommit_memory = 0 [kfg-ap4] out: vm.overcommit_ratio = 50 [kfg-ap4] out: vm.nr_overcommit_hugepages = 0
[kfg-ap4] out:
================================================ ========================
实际数据如下,除服务器名称外其余数据相同
[kfg-ap3] Executing task 'moc'
[kfg-ap3] sudo: /sbin/sysctl -A | grep overcommit
[kfg-ap3] out:
[kfg-ap3] out: We trust you have received the usual lecture from the local System
[kfg-ap3] out: Administrator. It usually boils down to these three things:
[kfg-ap3] out:
[kfg-ap3] out: #1) Respect the privacy of others.
[kfg-ap3] out: #2) Think before you type.
[kfg-ap3] out: #3) With great power comes great responsibility.
[kfg-ap3] out:
[kfg-ap3] out: sudo password:
[kfg-ap3] out: vm.overcommit_memory = 0
[kfg-ap3] out: vm.overcommit_ratio = 50
[kfg-ap3] out: vm.nr_overcommit_hugepages = 0
[kfg-ap3] out:
[kfg-ap4] Executing task 'moc'
[kfg-ap4] sudo: /sbin/sysctl -A | grep overcommit
[kfg-ap4] out:
[kfg-ap4] out: We trust you have received the usual lecture from the local System
[kfg-ap4] out: Administrator. It usually boils down to these three things:
[kfg-ap4] out:
[kfg-ap4] out: #1) Respect the privacy of others.
[kfg-ap4] out: #2) Think before you type.
[kfg-ap4] out: #3) With great power comes great responsibility.
[kfg-ap4] out:
[kfg-ap4] out: sudo password:
[kfg-ap4] out: vm.overcommit_memory = 0
[kfg-ap4] out: vm.overcommit_ratio = 50
[kfg-ap4] out: vm.nr_overcommit_hugepages = 0
[kfg-ap4] out:
【问题讨论】:
-
什么是 Python 问题?
-
@Trimax .. 很抱歉造成混乱,我正在尝试使用 awk、sed、python 来解决这个问题。python 没有问题
-
实际数据和预期结果是哪一部分?
-
@James .. 具有“[kfg-ap4]”服务器名称的整个集合是我们需要对其进行排序的数据的实际部分。
-
好的,你只高亮了你想打印的行。谢谢。