0

When attempting to use this script in conjunction with cat command, I am only getting the first entry, rather than all of them. here is the script:

for line in sys.stdin:
    line       = line.strip() #strip out carriage return
    key_value  = line.split(",")   #split line, into key and value, returns a list
    key_in     = key_value[0]
    value_in   = key_value[1]

#print key_in
if(value_in.isdigit()==True):
    print('%s\t%s' % (key_in, value_in)) 
elif(value_in == 'ABC'):
    print('%s\t%s' % (key_in, value_in))

I am then running cat command on the target files and the script. Thoughts?

2
  • I imagine you are getting the last not the first, your if and print are outside the loop Commented Apr 8, 2016 at 19:49
  • Can you give an example of your input, and the output you expect for it? Commented Apr 8, 2016 at 19:50

1 Answer 1

2

Your indentation looks incorrect. Perhaps this is what you're looking for?

for line in sys.stdin:
    line       = line.strip() #strip out carriage return
    key_value  = line.split(",")   #split line, into key and value, returns a list
    key_in     = key_value[0]
    value_in   = key_value[1]

    #print key_in
    if(value_in.isdigit()==True):
        print('%s\t%s' % (key_in, value_in)) 
    elif(value_in == 'ABC'):
        print('%s\t%s' % (key_in, value_in))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.