fixblock.pl -- Convert Stream File to Fixed Block File
fixblock.pl is a script to convert a "stream" data file, in which all data is on one long line with no end of line delimiters, into a fixed block data file with a constant logical record length (LRECL). This started as a one or two line perl hack with hard-coded parameters, but after giving it to several coworkers, I found that it required more hand-holding (like commandline parameters, usage messages, error messages, etc.). Hence, it's quite a bit longer now.
This small program has been useful for fixing files incorrectly read from tape and some data files that have been received in stream format via FTP. The program leaves the original data file in its original format. NOTE that the script will fail to produce useful output if, for example, trailing blanks on short data lines were stripped before the input data file was put into stream format. Each data line or record must be LRECL length even when in stream format, in other words.
Assuming this program is executable its commandline is:
fixblock.pl -l# infile outfile
-l# sets the LRECL desired to # characters
infile is the stream file to be processed
and outfile is the file to which the blocked output will be sent.
As an example of usage, the command fixblock.pl -l5 test.dat test.out with an input file, test.dat (one line with no line-end character) consisting of:12345123451234512345123451234512345will produce this output in test.out:12345 12345 12345 12345 12345 12345 12345The user will see the following output on the screen:(pts/1):~> fixblock.pl -l5 test.dat test.out fixblock.pl: Done! 7 records processed from 'test.dat' Output is in 'test.out'
Back to Kent's Perl Page