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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:49:57+00:00 2026-05-31T02:49:57+00:00

I read a line of data in this form: KEYNAME:value,KEYNAME:value,KEYNAME:value (please note keys are

  • 0

I read a line of data in this form:

KEYNAME:value,KEYNAME:value,KEYNAME:value

(please note keys are strings without spaces and values are integers)

I need to select some specific keys (without knowing their relative positions) and print their values on separate lines:

value
value
value

So far I came to something like converting the input line to multiple KEY:value lines, grepping the keys I want, imposing a known order and finally passing that through cut again to remove the key part:

sed 's/,/\n/g' | egrep '(FooKey|BarKey|BazKey)' | sort | cut -d':' -f2

I thought I could arrange something with awk, of which I just know the basics, but I can only manage fields by their positional order and not by their name (key name).

Could be done with other languages (i.e. Python or Perl) but I’m taking it as an exercise to do everything with the usual shell tools. Besides, I would still prefer the above solutions to loading up a bigger interpreter like python or perl.

  • 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-31T02:49:58+00:00Added an answer on May 31, 2026 at 2:49 am

    This will print only the values:

    awk 'BEGIN { RS=","; FS=":" } { print $2 }'
    

    If you want the values in a specific order, you can put them in an array:

    awk '
        BEGIN { RS=","; FS=":" }
        { values[$1] = $2 }
        END {
            print values["FooKey"];
            print values["BarKey"];
        }'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to read a file line-by-line, and storing that line of data
I have part of my script that goes like this: while read line do
function new_photo() { if( !empty($this->data)) { $this->data['Photo']['showcase_id'] = $this->Session->read('CurrShowcase.id'); $this->data['Photo']['added'] = date(Y-m-d H:i:s); $this->Showcase->Photo->save($this->data);
Are there any special considerations trying to read up data from an HTML form
This is a follow up question to: Dynamically updating a4j:repeat using data from form
I can read some data in like this in the repl. For a real
I have a question, how to read a specific column form data set.... I
Hard-to-read-line @daily export sunshine=~/logs/Sunshine-`date '+\%F'` && export sunshineUrl=http://www.sunshine.net/main/search_results.asp?currency_id=1&min_price=&max_price=50000&country_id=241&region_id=&Submit=Search && mkdir -p $sunshine && cd
Say you have a simple loop while read line do printf ${line#*//}\n done <
I want to write a function that read line by line from a socket

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.