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
  • Why are there no group separators -- in your output when you use -A1? – Freddy Apr 29 '19 at 12:09
  • Sorry, there is a -- separator. – Art Honrado Apr 30 '19 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 – Art Honrado Apr 30 '19 at 2:09
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 ' ' - -.

| improve this answer | |
  • Thank you so much this work! grep --no-group-separator -A1 'ping statistics' *.log | paste -d " " - - – Art Honrado Apr 30 '19 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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.