Nov-22-2018, 09:45 AM
Are you sure that the files are not empty?
This is what I am trying - Python 3.5.2:
This is what I am trying - Python 3.5.2:
In [1]: cd tmp/ /home/victor/tmp In [2]: p = ['Eth1/1', 'Eth1/5','Eth2/1', 'Eth2/4','Eth101/1/1', 'Eth101/1/2', 'Eth101/1/3','Eth102/1/1', 'Eth102/1/2', 'Eth102/1/3','Eth103/1/1', 'Eth103/1/2', 'Eth103/1/3','Eth103/1/4','Eth104/1/1', 'Eth104/1/ ...: 2', 'Eth104/1/3','Eth104/1/4'] In [3]: with open('abc1.txt', 'w+') as fw1, open('abc2.txt', 'w+') as fw2: ...: for element in p: ...: if len(element.strip('Eth').split('/')[0]) == 1: ...: fw1.write('int {}\n mode\n'.format(element)) ...: else: ...: fw2.write('int {}\n mode\n'.format(element)) ...: In [4]:This is what is in the files:
In [4]: cat abc1.txt int Eth1/1 mode int Eth1/5 mode int Eth2/1 mode int Eth2/4 mode In [5]: cat abc2.txt int Eth101/1/1 mode int Eth101/1/2 mode int Eth101/1/3 mode int Eth102/1/1 mode int Eth102/1/2 mode int Eth102/1/3 mode int Eth103/1/1 mode int Eth103/1/2 mode int Eth103/1/3 mode int Eth103/1/4 mode int Eth104/1/1 mode int Eth104/1/2 mode int Eth104/1/3 mode int Eth104/1/4 modeI don't know how you determine the ranges.