user1220402 user1220402 - 2 months ago 12
Bash Question

Append two para side by side using shell,sed,awk

Hello i have below raw output

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


want to combine and create the single line. and append
expected output

Assume this as single line:

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


Another line:

3 48 10/100/1000BaseT Premium POE E Series WS-X4748-RJ45V+E CAT1743L2JQ 3 24e9.b335.bfd0 to 24e9.b335.bfff 1.3

sat sat
Answer

You can use this awk:

awk '$1 ~ /^[0-9]/{a[$1]=a[$1]?a[$1] FS $0 : $0} END{for(v in a)print a[v]}' file