-
Notifications
You must be signed in to change notification settings - Fork 0
Python Splitter
If you have ever worked with a files create (generally in the bank industry) in a Mainframe, those files are always HUGE 50MB or so. They were created as a result of a batch process or for an input to a batch process.
Working with these kind of files on a regular text editor like Sublime Text or Notepad++ is impossible, you will notice they will HUNG or in the best scenario work VERY slowly. This is because advance text editors always try to process the file entirely at once, this will make the majority of Text Editors unresponsive and maybe you just need to verify some value within the file or just look the content for a quick analysis.
So Splitter comes in to provided a solution, This is split these files into multiples (thousands) lines to allow you to work with any text editor.
Just execute the splitter.py with the -i[nputfile] STRING "Input Filename" -b[bytes] INT "Number of Bytes for each line", optionally use -h[elp]
Example 1:
MacBook-Pro-Retina:python$ _**python splitter.py -h**_
Python 2.7.10 (default, Oct 23 2015, 19:19:21)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)]
usage: splitter.py [-h] -i STRING -b INT
Splitter script will split one file in multiple lines
optional arguments:
-h, --help show this help message and exit
-i STRING, --inputfile STRING
Input filename
-b INT, --bytes INT Number of bytes per line
MacBook-Pro-Retina:python$
Example 2:
Input file content = "01234567890123456789012345678901234567890123456789012345678901234567890..." 600 bytes long.
MacBook-Pro-Retina:python$ **python splitter.py -i datafile -b 10**
Python 2.7.10 (default, Oct 23 2015, 19:19:21)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)]
('Input file is ', 'datafile')
('Output file is ', 'datafile-splitted')
('Number of bytes ', '10')
Starting script excution...
Splitted 600 bytes in 60 lines
End excution.
MacBook-Pro-Retina:python$
Output file content = 60 lines with 0123456789
IMPORTANT:
- Input file needs to exist
- Output file will be created at the same location where the input file resided with "-splitted" appended to the name.
Happy Coding.