In the past I have been too willing to use bash scripts for grepping and awking CSV files. The code snippet below is a starter for doing similar with python and while far from perfect, demonstrates calling another system command and manipulating strings:
#!/usr/bin/python
import csv
import os
with open('input.csv') as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
for row in csv_reader:
if "filterword" in row[3]:
field_name = row[2]
field_dob = row[4]
field_url = row[3]
url_parts = row[3].split(".")
url_region = url_parts.split("-")
cust_ref = os.popen("/usr/local/bin/somescript.pl %s | grep 'Tier' | awk -F ':' '{print $2}'| tr -d '\n '" % field_name).read()
print("%s,%s,%s,%s" % (customer_ref,url_region,field_dob,field_url))
else:
print("Line does not match expected input")