-2

Looking for option to get rid of traceroute: wrote 0 40 chars, ret=-1 message in its output. So the output would look just like this:

 1  * * *
 2  * * *

Best I could achieve is these:

$ traceroute -anm 10 -w 1 0 2>/dev/null | sed 's/traceroute:.*/ /'
 1
 *
 *
 *
 2
 *
 *
 *

and

$ traceroute -anm 10 -w 1 0 2>/dev/null | sed -e 'N;s/traceroute:.*\n/ /'
 1   *traceroute: wrote 0 40 chars, ret=-1
 *  *
 2   *traceroute: wrote 0 40 chars, ret=-1
 *  *

1 Answers1

0

Assuming that you are happy with how it starts out, you can reassemble the results like this. I am not claiming this is a good design, but if you are still trying, I think it should work, and it keeps the code structure you already had:

 $ traceroute -anm 10 -w 1 0 2>/dev/null |  sed 's/traceroute:.*/ /' |\
 awk '/[0-9]/ {printf ("\n%s ", $0)} /*/ {printf("%s ", $0)} END {printf ("\n")}'

Which basically says if it is a star, just print it and a spacer, if it is number, print a line feed (to start a new record) and then print the number. At the end, it prints an extra line feed, in case you were in the middle.

It should work fine with multi-digit line numbers as well.

I think I'd probably have tried the whole thing in awk, but if it gets the job done and it is not a production thing, seems this should suffice.

MJB
  • 7,639
  • 2
  • 31
  • 41