Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am running a script whose output is:

Circuit                           Packets/Bytes Sent Packets/Bytes Received
2/1 vlan-id 1005                         11589119559            14650974869
                                       3084237796552         13027195853643

This script is being run every five minutes, for MRTG purposes. Now I need to get the value of the second row for columns 2 and 3 separately:

Bytes Sent 3084237796552

Bytes Received 13027195853643

How can I do that using sed?

share|improve this question
Why do you want to use sed? – Daniel Beck Dec 22 '11 at 6:17

One solution using sed:

sed -n '$ { s/^\s*/Bytes Sent /; s/\([0-9]\)[ ]/\1\n/; s/\(\n\)\s*/\1Bytes Received /; p }' infile


-n                               # Disable printing lines.
$                                # In last line...
s/^\s*/Bytes Sent /              # Substitute all spaces from the beginning with literal string 'Bytes Sent'
s/\([0-9]\)[ ]/\1\n/             # Substitute first match of a space after a number with a new line.
s/\(\n\)\s*/\1Bytes Received /   # Substitute all space after the new line with literal string 'Bytes received'
p                                # Print this line (two lines after the included '\n')


Bytes Sent 3084237796552
Bytes Received 13027195853643
share|improve this answer

I never got the hang of sed and multiple lines, but if you just want it done this should work. | tail -1 |  awk '{ print "Bytes sent "$1 "\nBytes recieved "$2 }'
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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