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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:42:18+00:00 2026-06-17T01:42:18+00:00

probably simple question for someone who knows, but I’m having a hard time retrieving

  • 0

probably simple question for someone who knows, but I’m having a hard time retrieving some variable values from a file. My file is something like:

variable1 12
variable2 43
variable3 897

and I want to get the value of variable2, 43.

I tried some commands with sed but with no luck:

sed -n 's/variable2 //;s/variable3//' myFile
  • 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-17T01:42:20+00:00Added an answer on June 17, 2026 at 1:42 am

    With only sed:

    $ sed -n 's/^variable2 //p' file
    43
    

    Your problem is you are using -n to suppress the output of sed so you need the p flag so sed prints the lines where the substitution took place.

    As this just pattern matching I would go with only grep for this:

    $ cat file
    variable1 12
    variable2 43
    variable3 897
    
    $ grep -Po '(?<=^variable2 )\d+' file
    43
    

    Or even just awk:

    $ awk '$1=="variable2"/{print $2}' file
    43
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is probably a silly question, but I am having a hard time finding
This is probably a simple question for someone who is an sql database administrator,
This is another probably very simple question, but I haven't been able to find
This is probably a simple question but I can't seem to figure out how
This is probably a simple question, but i have been unable to find a
This is probably a simple question but I am developing a web app in
This is probably a very simple question so please forgive my ignorance, but can
This is probably a very simple question but I'm a little confused how this
This is probably a really simple question but one I've never quite worked out
I know this is probably a very simple question but how would I do

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.