0

I have 10 files with several IP ping test results

--- 10.90.101.224 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
Some Text here...
--- 10.90.101.225 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
Some Text here...
--- 10.90.101.226 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms

i used > grep -A1 'ping statistics' *.log and got the output below

--- 10.90.101.224 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
--- 10.90.101.225 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms
--- 10.90.101.226 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2002ms

i wanted to get the output with the format below

--- 10.90.101.224 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2002ms
--- 10.90.101.225 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2002ms
--- 10.90.101.226 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2002ms
3
  • Why are there no group separators -- in your output when you use -A1?
    – Freddy
    Commented Apr 29, 2019 at 12:09
  • Sorry, there is a -- separator. Commented Apr 30, 2019 at 2:08
  • --- 10.90.101.224 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2002ms -- --- 10.90.101.225 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2002ms -- --- 10.90.101.226 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2002ms Commented Apr 30, 2019 at 2:09

2 Answers 2

2

Use paste:

grep -A1 'ping statistics' *.log | paste - -

paste will per default add a tab between the lines, change this to a space with paste -d ' ' - -.

1
  • Thank you so much this work! grep --no-group-separator -A1 'ping statistics' *.log | paste -d " " - - Commented Apr 30, 2019 at 4:15
0

Using xargs

grep -A1 'ping statistics' *.log | xargs -n 15

-n max-args Use at most max-args arguments per command line.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .