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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:15:37+00:00 2026-05-23T21:15:37+00:00

Im still new to python. I have a text file with a list of

  • 0

Im still new to python.
I have a text file with a list of numbers, and each number has two ‘attributes’ along with it:

250 121 6000.654
251 8472 650.15614
252 581  84.2

i want to search for the 1st column and return the 2nd and 3rd columns as separate variables so i can use them later.

cmd = """ cat new.txt | nawk '/'251'/{print $2}' """
os.system(cmd)

This works in that it prints the $2 column, but i want to assign this output to a variable, something like this (however this returns the number of errors AFAIK):

cmdOutput =  os.system(cmd)

also i would like to change the nawk’d value based on a variable, something like this:

cmd = """ cat new.txt | nawk '/'$input'/{print $2}' """

If anyone can help, thanks.

  • 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-23T21:15:38+00:00Added an answer on May 23, 2026 at 9:15 pm

    Don’t use cat and nawk. Please.

    Just use Python

    import sys
    target= raw_input( 'target: ' ) # or target= sys.argv[1]
    with open('new.txt','r') as source:
        for columns in ( raw.strip().split() for raw in source ):
            if column[0] == target: print column[1]
    

    No cat. No nawk.

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

Sidebar

Related Questions

Still new to python and django, though learning ;-) I have a view that
I'm new to Python, I still have issues with the semantics of class inheritance.
Still fairly new to django and python. I've defined two nearly identical models that
I am still new to Python and have been reviewing the following code not
still new to XML parsing with the iphone so i have a few questions.
I am still new to LINQ, and I have wrestled with a query for
I'm still fairly new to Python, and my OO experience comes from Java. So
I'm very new to Python and multithreaded programming in general. Basically, I have a
I'm using the Tornado framework (Python) on GAE. I'm still kind of new to
I'm still fairly new to Python and I'm trying to get used to its

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.