python - how to get values in csv to a report

Trying to get a report from a csv file.

csv file: servers.csv
name,date,zone
server1,3/3/2016,dmz
server2,4/3/2017,prod
server3,4/4/2017,nonprod
server4,6/6/2017,prod

I'm trying to get a list of prod servers that contains the server name and zone.
LVL 1
LN41Asked:
Who is Participating?
 
LN41Author Commented:
I think I got it. Thanks for the help.

import csv
with open('servers.csv', newline='') as f:
    reader = csv.reader(f)
    for row in reader:
        if row[3] == 'prod':
            print(row[1],row[3])
0
 
David FavorLinux/LXD/WordPress/Hosting SavantCommented:
Try ingesting data in your python script using this pipeline...

cat servers.csv | grep -v ^name | grep ",prod"

Open in new window

0
 
aikimarkCommented:
import csv

f = file('c:\users\mark\downloads\Q_29075243.csv')
for l in csv.reader(f):
    print l[0],l[2]

Open in new window

Produces:
name zone
server1 dmz
server2 prod
server3 nonprod
server4 prod

Open in new window

0
 
LN41Author Commented:
Hi aikimark,Your answer is helpful but looking for a way to filter only for prod servers rather than manually id them. ideal result produces:

name zone
server2 prod
server4 prod
0
 
LN41Author Commented:
figured it out myself
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.