Regex attempt 7

This commit is contained in:
Minoplhy 2021-08-12 17:46:03 +07:00
parent 76c15e5916
commit 8a982a849b

View File

@ -18,6 +18,15 @@ with open(infile, 'w') as f1:
f1.writelines(["%s\n" % item for item in file])
f.close()
remove_words = ['localhost','localhost.localdomain','local','broadcasthost','loopback','ip6-localnet','ip6-mcastprefix','ip6-allnodes','ip6-allrouters','ip6-allhosts','ip6-loopback']
with open(infile, 'r') as f:
lines = f.read().splitlines()
with open(outfile, 'w') as f:
for line in lines:
if not line.endswith((tuple(remove_words))):
f.write('\n'.join([line + '\n']))
with open(infile) as f:
file = f.read().split('\n')
for i in range(len(file)):
@ -43,15 +52,6 @@ with open(infile, 'w') as f: # load file in write mode
f.write('\n'.join([line + '\n']))
f.close()
remove_words = ['localhost','localhost.localdomain','local','broadcasthost','loopback','ip6-localnet','ip6-mcastprefix','ip6-allnodes','ip6-allrouters','ip6-allhosts','ip6-loopback']
with open(infile, 'r') as f:
lines = f.read().splitlines()
with open(outfile, 'w') as f:
for line in lines:
if not line.endswith((tuple(remove_words))):
f.write('\n'.join([line + '\n']))
with open(infile) as f:
file = f.read().split('\n')
for i in range(len(file)):