您好我的原始输出
Mod Ports Card Type Model Serial No.
---+-----+--------------------------------------+------------------+-----------
1 8 Sup 8-E 10GE (SFP+), 1000BaseX (SFP) WS-X45-SUP8-E CAT1903LAEN
3 48 10/100/1000BaseT Premium POE E Series WS-X4748-RJ45V+E CAT1743L2JQ
M MAC addresses Hw Fw Sw Status
--+--------------------------------+---+------------+----------------+---------
1 c08c.60ef.f340 to c08c.60ef.f347 1.2 15.1(1r)SG7 03.09.01.E.112 Ok
3 24e9.b335.bfd0 to 24e9.b335.bfff 1.3
Mod Ports Card Type Model Serial No.
---+-----+--------------------------------------+------------------+-----------
1 8 Sup 8-E 10GE (SFP+), 1000BaseX (SFP) WS-X45-SUP8-E CAT1903LAEN
3 48 10/100/1000BaseT Premium POE E Series WS-X4748-RJ45V+E CAT1743L2JQ
M MAC addresses Hw Fw Sw Status
--+--------------------------------+---+------------+----------------+---------
1 c08c.60ef.f340 to c08c.60ef.f347 1.2 15.1(1r)SG7 03.09.01.E.112 Ok
3 24e9.b335.bfd0 to 24e9.b335.bfff 1.3 Ok
想要组合并创建单行。并附加 预期产出
但是,如果我一次完成所有操作,那么从块2开始的所有行也会被追加,以及来自chunk-1的行。 所以想先处理chunk-1,然后再处理chunk-2。
假设这是单行:
1 8 Sup 8-E 10GE (SFP+), 1000BaseX (SFP) WS-X45-SUP8-E CAT1903LAEN 1 c08c.60ef.f340 to c08c.60ef.f347 1.2 15.1(1r)SG7 03.09.01.E.112 Ok
另一条线:
3 48 10/100/1000BaseT Premium POE E Series WS-X4748-RJ45V+E CAT1743L2JQ 3 24e9.b335.bfd0 to 24e9.b335.bfff 1.3
类似的方式也需要chunk-2输出。
答案 0 :(得分:1)
您可以使用此awk
:
awk '$1 ~ /^[0-9]/{a[$1]=a[$1]?a[$1] FS $0 : $0} END{for(v in a)print a[v]}' file