python - Bash script to open new terminals for separate operations generated with Python3 -
i have written python code making operations on data file. logging procedure if there problem have previous information start.
here code operation:
output2file = open('output/output.csv', 'a', encoding='utf-8', errors='ignore') datafile = open('input','r',encoding='ascii',errors='ignore') count = 0 line in datafile.readlines(): count += 1 splittedline = line.lower().strip().split(' | ') emails = list(splittedline[1]) check = myprocess(splittedline[0],splittedline[1]) print(str(count)) if count%100 == 0: logmaintain = open('log','w') logmaintain.write(str(count)) logmaintain.close() result in resultant: output2file.write(str(result)) resultant = [] if check == '': pass datafile.close() output2file.close()
most of time owing power cut , less backup, came across issue of loss of lines written. hence, kept log , remove lines input
, start process again. idea me if there files below 10. can 50 files, , if happen havoc me manually.
hence know how can create bash script automate process.
here description of trying do:
1) open single file process in separate terminal.
2) check line number in log file , remove many number of lines input file. used command sed -e "1,20000d;" input > input1
3) rename files. previous file added string old , new file name of original file:
mv input input_old mv input1 input
4) start process again. if there no log file process must executed is.
i have maintain log in log folder , output in output folder. input file kept outside python script run.
i hope hear soon. kindly me.
note: resultant
global list , stores data process temporarily , writes file after 100 lines completed , agian become empty storing next slot of 100 lines.
Comments
Post a Comment