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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:18:45+00:00 2026-05-20T22:18:45+00:00

Consider a stream of lines piped to awk . Lines are composed of sequence

  • 0

Consider a stream of lines piped to awk. Lines are composed of sequence of interleaved field names and field values, like the following example (lines really are much longer with many other attributes listed):

Samples 2978 Min -0.068689 at 1389 Amin 1.0406e-08 at 435 Max 0.0514581 at 1375
Samples 2977 Min -0.100258 at 1293 Amin -1.06743e-08 at 3 Max 0.0989735 at 1282
Samples 2977 Min -0.109783 at 1281 Amin -2.97293e-08 at 10 Max 0.139651 at 1268
Samples 2976 Min -0.116509 at 1269 Amin -1.04306e-09 at 161 Max 0.0985577 at 1255

I’d like to extract a certain value from the strings using it’s name as a guide, for example, Min. If I had a scanf-like function in awk, I’d have at first used ind=index($0, "Min"), then s=substr($0, ind), then sscanf(s,"Min %f", &val) to obtain val. However, I dont have any scanf available in awk.

How can I extract the value by it’s name then?

  • 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-20T22:18:46+00:00Added an answer on May 20, 2026 at 10:18 pm

    You go through each field, check for “Min” and then extract the next field

    $ awk '{for(o=1;o<=NF;o++) if ($o =="Min" ) {print $(o+1)} }' file
    -0.068689
    -0.100258
    -0.109783
    -0.116509
    

    Ruby(1.9+)

    $ ruby  -ne 'puts $_.scan(/Min\s+(.[^\s]*)/)' file
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider an interface like IMyInterface = interface procedure DoSomethingRelevant; procedure Load (Stream : TStream);
Consider the following example from APUE book: #include <errno.h> #include <sys/socket.h> int initserver(int type,
Consider the following example: #include <iostream> #include <sstream> #include <vector> #include <wchar.h> #include <stdlib.h>
Consider the following example: as part of configuration for my program the user supplies
Consider I have Struct like the following: struct Bitmask { unsigned char payload_length: 7;
Consider the following code: Stream stream = GetStreamFromSomewhere(); XmlDictionaryReader mtomReader =XmlDictionaryReader.CreateMtomReader ( stream, Encoding.UTF8,
Consider the following setup: A windows PC with a LAN interface and a WiFi
Consider the Oracle emp table. I'd like to get the employees with the top
Consider the following ruby code test.rb: begin puts thisFunctionDoesNotExist x = 1+1 rescue Exception
Consider the term 'dashboard' as a generic UI pattern where multiple views stream different

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.