import reyourfile = "a.txt"yourtarget = "xxx"with open(yourfile,"r") as fi: for line in fi: if line.strip(): tmp = re.split("\s+",line.strip()) if tmp[0] == yourtarget: print("|"+"|".join(tmp)+"|")