Batch / Find And Edit Lines in TXT file

On a native Windows install, you can either use batch(cmd.exe) or vbscript without the need to get external tools. Here’s an example in vbscript: Set objFS = CreateObject(“Scripting.FileSystemObject”) strFile = “c:\test\file.txt” Set objFile = objFS.OpenTextFile(strFile) Do Until objFile.AtEndOfStream strLine = objFile.ReadLine If InStr(strLine,”ex3″)> 0 Then strLine = Replace(strLine,”ex3″,”ex5″) End If WScript.Echo strLine Loop Save as … Read more

Splitting large text file into smaller text files by line numbers using Python

lines_per_file = 300 smallfile = None with open(‘really_big_file.txt’) as bigfile: for lineno, line in enumerate(bigfile): if lineno % lines_per_file == 0: if smallfile: smallfile.close() small_filename=”small_file_{}.txt”.format(lineno + lines_per_file) smallfile = open(small_filename, “w”) smallfile.write(line) if smallfile: smallfile.close()