#!/usr/bin/env python#-*-coding:utf-8-*-#Author:forsakenImportgetoptImportOSImportSYSdefMain ():Try: opts, args= Getopt.getopt (sys.argv[1:],'hf:s', [' Help','file=','Sort']) exceptgetopt. Getopterror as E:Print('[-]%s'%e) Usage () Sys.exit (2) file="'Sort=False forO, ainchopts:ifOinch('- H','--help'): Usage () sys.exit ()elifOinch('- F','--file'): File=aelifOinch('- S','--sort'): Sort=TrueElse: Pass if notFile:Print('[-] File Arguments not found!') usage () Sys.exit (2) if notos.path.exists (file):Print('[-] File not found!') Sys.exit (1) with open (file,'R') as F:old=f.readlines () Old_len=len (old) New=list () forOinchOld :if notOinchnew:new.append (o) New_len=Len (new) Delete= Old_len-New_lenifSort:new.sort () out='New_'+file with open (out,'W') as F:f.writelines (new)Print('Delete%s Line'%Delete)Print('Please Check%s'%Out )defusage ():Print('Usage:python%s [options]'%sys.argv[0])Print("') Print('Options:') Print('-H,--help Show help Message and Exit') Print('-F file,--file=file file') Print('-S,--sort sort')if __name__=='__main__': Main ()
Text de-reordering tool