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 9252325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:55:00+00:00 2026-06-18T10:55:00+00:00

I would like to read data from stdin and execute a shell command for

  • 0

I would like to read data from stdin and execute a shell command for each parsed line and recover its output.

Here an example which almost works:

[root@eulbi002] # ping eulbi001 | awk -F'[ =]' '/64 bytes/{"date +%s"|getline D; print D,$11}'
1360069298 0.056
1360069298 0.051
1360069298 0.051

The command ‘date +%s’ is executed and I can recover the output, but it looks to me like the execution happens only once, not on every match.

The ultimate aim is to hand the output over to rrdtool for storage and rrdtool wants a timestamp for each record.

@Ed Morton, in addition to point out a working solution, mentioned gawk with its built-in time functions. This is the most elegant solution.

[root@eulbi002] # ping eulbi001 | awk -F'[ =]' '/64 bytes/{print systime(),$11}'
1360069298 0.056
1360069298 0.051
1360069298 0.051
  • 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-06-18T10:55:01+00:00Added an answer on June 18, 2026 at 10:55 am

    Just in case there’s yet another getline caveat kicking in here (see http://awk.info/?tip/getline), try closing the pipe after every invocation, e.g.:

    ping eulbi001 |
    awk -F'[ =]' 'BEGIN{cmd="date +%s"} /64 bytes/{cmd|getline D; close(cmd); print D,$11}'
    

    and see if you get different results. You still shouldn’t expect D to change on every invocation though, just every second. You could add a “.%N” for smaller granularity of your timestamps if you like.

    Better yet, use GNU awk with it’s builtin time functions so you don’t need to deal with this stuff at all.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to read asynchronously from stdin with Qt. I don't want to
I would like to read data from a plist, add some elements and the
I would like to read some data from a stream I have using std::getline
At class instantiation, I would like to read data from a file and process
I would like to read some data from other websites for a project using
i would like to connect to a website and process or read data from
I have a file which I would like to read data from. This is
I would like to know the best way to read data from an uploaded
I would like to read some data from a GoogleFusion table and then use
I would like to read/write data from my Oracle DB into my iPhone code.

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.