I'm new to Python so please bear with me. I have a text file named names.txt. The contents of that file are:
6,pon01.bf:R1.S1.LT1.PON10.ONT12
10,pon01.bf:R1.S1.LT1.PON10.ONT16
11,pon01.bf:R1.S1.LT1.PON10.ONT17
12,pon01.bf:R1.S1.LT1.PON10.ONT18
I need to be able to replace the "R", "S", "LT", "PON" and "ONT" with a "/", remove everything else and add "/1/1" to each line. The end result should look like this:
1/1/1/10/12/1/1,
1/1/1/10/16/1/1,
1/1/1/10/17/1/1,
1/1/1/10/18/1/1,
Below is my code:
import os
import re
import sys
file = open("/home/Scripts/names.txt", "r")
delnode = file.readline()
port = "/1/1"
for line in delnode:
delnode = delnode.split('R')[-1]
delnode = delnode.replace(".S", "/").replace(".LT", "/").replace(".PON", "/").replace(".ONT", "/")
print delnode + port
file.close()
The output of this script is:
1/1/1/10/12
/1/1
It only reads the first line in the text file. Appreciate any help!