#!/usr/bin/env python for line in open("file"): if "N1*PR*" in line: ind=line.index("N1*PR*") print line[ind+6:].split("*")[0]
# ./test.py CALIFORNIA