Skip to main content
added 4 characters in body
Source Link
steve
  • 22.3k
  • 5
  • 53
  • 79

awk solution

$ awk '/:/{d=$1}/Speed/{printf"%-28s%s\n",d,substr($0,length($0)-4)}' file
foo-6-25.example.com:       ( 49)
foo-5-4.example.com:        ( 19)
foo-8-28.example.com:       ( 43)
foo-9-7.example.com:        ( 91)
foo-5-19.idmz.example.com:  ( 19)
foo-7-3.example.com:        ( 20)
$

awk + column solution

Aligns the columns dynamically.

$ awk '/:/{d=$1}/Speed/{print d,substr($0,length($0)-4)}' file|column -tto' '
foo-6-25.example.com:       (  49)
foo-5-4.example.com:        (  19)
foo-8-28.example.com:       (  43)
foo-9-7.example.com:        (  91)
foo-5-19.idmz.example.com:  (  19)
foo-7-3.example.com:        (  20)
$

awk solution

$ awk '/:/{d=$1}/Speed/{printf"%-28s%s\n",d,substr($0,length($0)-4)}' file
foo-6-25.example.com:       ( 49)
foo-5-4.example.com:        ( 19)
foo-8-28.example.com:       ( 43)
foo-9-7.example.com:        ( 91)
foo-5-19.idmz.example.com:  ( 19)
foo-7-3.example.com:        ( 20)
$

awk + column solution

Aligns the columns dynamically.

$ awk '/:/{d=$1}/Speed/{print d,substr($0,length($0)-4)}' file|column -t
foo-6-25.example.com:       (  49)
foo-5-4.example.com:        (  19)
foo-8-28.example.com:       (  43)
foo-9-7.example.com:        (  91)
foo-5-19.idmz.example.com:  (  19)
foo-7-3.example.com:        (  20)
$

awk solution

$ awk '/:/{d=$1}/Speed/{printf"%-28s%s\n",d,substr($0,length($0)-4)}' file
foo-6-25.example.com:       ( 49)
foo-5-4.example.com:        ( 19)
foo-8-28.example.com:       ( 43)
foo-9-7.example.com:        ( 91)
foo-5-19.idmz.example.com:  ( 19)
foo-7-3.example.com:        ( 20)
$

awk + column solution

Aligns the columns dynamically.

$ awk '/:/{d=$1}/Speed/{print d,substr($0,length($0)-4)}' file|column -to' '
foo-6-25.example.com:       ( 49)
foo-5-4.example.com:        ( 19)
foo-8-28.example.com:       ( 43)
foo-9-7.example.com:        ( 91)
foo-5-19.idmz.example.com:  ( 19)
foo-7-3.example.com:        ( 20)
$
Source Link
steve
  • 22.3k
  • 5
  • 53
  • 79

awk solution

$ awk '/:/{d=$1}/Speed/{printf"%-28s%s\n",d,substr($0,length($0)-4)}' file
foo-6-25.example.com:       ( 49)
foo-5-4.example.com:        ( 19)
foo-8-28.example.com:       ( 43)
foo-9-7.example.com:        ( 91)
foo-5-19.idmz.example.com:  ( 19)
foo-7-3.example.com:        ( 20)
$

awk + column solution

Aligns the columns dynamically.

$ awk '/:/{d=$1}/Speed/{print d,substr($0,length($0)-4)}' file|column -t
foo-6-25.example.com:       (  49)
foo-5-4.example.com:        (  19)
foo-8-28.example.com:       (  43)
foo-9-7.example.com:        (  91)
foo-5-19.idmz.example.com:  (  19)
foo-7-3.example.com:        (  20)
$