Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6729731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:19:31+00:00 2026-05-26T10:19:31+00:00

I would like to join and process the two lines coming out of the

  • 0

I would like to join and process the two lines coming out of the top command:

shell> top -p 1 -b -d 1 | egrep '^top|^Cpu'
top - 15:17:45 up 736 days,  4:32,  3 users,  load average: 0.06, 0.03, 0.00
Cpu(s):  0.7% us,  0.8% sy,  0.0% ni, 97.1% id,  1.3% wa,  0.0% hi,  0.0% si

When trying to use awk and sed commands, I run into trouble – no output is produced. What commands would I use to get the output to look like this:

Time: 15:17:45 Cpu(s):  0.7% us,  0.8% sy,  0.0% ni, 97.1% id,  1.3% wa,  0.0% hi,  0.0% si

Here is a piece of code that could be useful:

shell> echo 'top - 15:17:45 up 736 days,  4:32,  3 users,  load average: 0.06, 0.03, 0.00' | awk -F' up' '/^top/ {print "Time: " $1}' | sed 's/top - //'
Time: 15:17:45
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T10:19:31+00:00Added an answer on May 26, 2026 at 10:19 am

    try this:

    command | sed -n "N;s/top - /Time: /;s/up.*\n//;p" 
    

    At first it reads in the seconds line, then it substitutes “top – ” by “Time: “, finally it deletes everything from up unto the first line break.

    Output:

    Time: 15:17:45 Cpu(s):  0.7% us,  0.8% sy,  0.0% ni, 97.1% id,  1.3% wa,  0.0% hi,  0.0% si
    

    EDIT:

    Try this:

    top -p 1 -b -d 1 | awk '
        /^top/{a=$0}
        /^Cpu/{
            sub(/top - /,"Time:",a);
            sub(/up.*$/,"",a);
            printf "%s %s\n",a,$0;a=""}'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to join two xml files as illustrated below. However the question
I have two tables user and log. I would like to join the user
I would like to know whether I could perform a full outer join between
I have a materialized view of a complex join, which I would like to
I would like to know how to reverse the process of the below DecodeBinaryBase64
I would like to use thread to process a streaming input. How can make
I have a question regarding left join on SQL: I would like to know
I would like to stop the execution of a process with Ctrl + C
I would like to test a process that queries across multiple schemas using PHPUnit's
Is it possible to join two sockets? For example, if a process is acting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.