import re, sys try: f = open("/etc/passwd",'r') except: print "\nCan't open the file!\n" sys.exit(0) #enter your username here username = "rash" k=0 for lines in f.readlines(): match = re.search(username, lines) if match: k=1 print match.group() + " exists." break if(k==0): print username + " does not exist!"