-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest1.py
More file actions
79 lines (63 loc) · 1.86 KB
/
test1.py
File metadata and controls
79 lines (63 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Nov 12 14:34:26 2019
@author: anshu
"""
import glob
import numpy as np
#path = '/home/anshu/Desktop/events/2018_events'
files = [f for f in glob.glob("**/2019*.txt", recursive=True)]
files.sort()
for f in files:
print(f)
num = np.size(files)
def find(substr, infile, outfile):
with open(infile) as a, open(outfile, 'w') as b:
for line in a:
if substr in line:
b.write(line + '\n')
k=['II',':Product:']
searchstrings = ('II', 'Product')
for i in files:
print('-'*90)#just a line to distinguish between all the outputs
print(i)
print('*'*len(i))#just some underlining
with open(i,'r') as f:
for line in f.readlines():
#print(line)
with open('test1.txt', 'a') as file:
file.write(line)
for word in searchstrings:
if word in line:
print(line,file=open("test2.txt", "a"))
bad_words = ['III','VII']
with open('test2.txt') as oldfile, open('test3.txt', 'w') as newfile:
for line in oldfile:
if not any(bad_word in line for bad_word in bad_words):
newfile.write(line)
with open('test3.txt', 'r+') as fd:
lines = fd.readlines()
fd.seek(0)
fd.writelines(line for line in lines if line.strip())
fd.truncate()
#####################################
## to combine everythng###
#import os
#filelist = os.listdir(os.getcwd())
#filelist.sort()
#
#for i in filelist:
# print('-'*90)#just a line to distinguish between all the outputs
# print(i)
# print('*'*len(i))#just some underlining
# try:
# with open(i,'r') as f:
# for line in f.readlines():
# print(line)
# with open('test.txt', 'a') as file:
# file.write(line)
#
# except:
# pass
#