我有一个巨大的文件,我需要排序和合并3行有模式匹配“vm”,并需要他们到一个单一的行,如下所示
kfg-ap4是服务器名,我们只能有一次,这将是很好的排序时。。 我尝试了awk与getline,但不知何故,我错过了适合它。。你知道吗
awk'/vm/{printf$0”“;getline;print$0}'内存溢出
**[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:
走查:
由于实际上一个组中有3行以上的行,请使用以下命令:
它缓冲记录并在遇到与
/vm/
不匹配的记录后打印出来。如果文件中有连续的组,则可能会出现问题。您可能会得到比预期更长的行。你知道吗另一个答案只使用
sed
像这样调用(将上述文件另存为
filter.sed
):如果
vm
匹配,则存储在保持缓冲区中。然后交换整个缓冲区以删除行中的换行符和无用的kfg前缀,再次交换。你知道吗如果不匹配,请再次交换缓冲区并打印。你知道吗
相当简单&效果很好(cornercase:如果log以vm行结尾,则可以省略)
你几乎做到了:只需在变量中累积,最后打印:
您还可以使用精确的构造并转换换行符:
相关问题 更多 >
编程相关推荐