The following code searches for words given in the list and when matched writes the line to a csv row by row.
I am trying to find a solution so that instead of writing by row only, the 1st item in the list is column1 and 2nd item to column2 and so on.
parm_list = ["electricalAntennaTilt ","iuantSectorId ", "eUtranCellFDDId "]
os.remove("Parm.csv")
#keyword = input("Enter keyword here: ")
with open('Parm.csv', 'w', newline='\n', encoding='utf-8') as csvfile:
writer = csv.writer(csvfile)
writer.writerow(["eNB", "Parameter", "Value"])
for filename in os.listdir(directory):
for i in parm_list:
if filename.endswith(".txt"):
with open(filename, "r", encoding="UTF-8") as file:
for line in file:
if re.search(i, line):
with open('Parm.csv', 'a', newline='\n', encoding='utf-8') as csvfile:
writer = csv.writer(csvfile)
writer.writerow([filename] + [line])
else:
continue
Current Output:
315655.txt electricalAntennaTilt 30
315655.txt iuantSectorId 315655_1_4
Expected output:
315655.txt electricalAntennaTilt 30 iuantSectorId 315655_1_4